I am trying to force HTTPS on a domain. It must be done using a method that works by domain name and not port number (due to host structure/setup).
My closest attempt was:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule ^.*$ https://www.mydomain.com/$1 [R=301,L]
This works when typing "mydomain.com" into the address bar, automatically redirecting to "https://mydomain.com" but when I type "www.mydomain.com" it does not work. I assume it is a syntax issue as I am very new to htaccess and have spent about 4 hours trying to create a solution from other's code.
Any chance of a pointer?
To make the setup a little more understandable.
/public_html/
- All files in this folder relate to www.mydomain.com
/public_html/subfolder
- These folders contain files also relating to mydomain.com
/public_html/subdomain
- These folders contain files relating to www.myotherdomain.com
My other domains are subdomains of mydomain.com
for to be listed in the cpanel on the host.
For example: subdomain.mydomain.com
is the same as www.myotherdomain.com
.
Hopefully that clears up the structure.