Reputation: 115
I've just set up my domain to use ssl and have added this code to a .htaccess file (at root):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*\.)*mysite.com$ [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://www.mysite.com/$1 [R]
it redirects all traffic from mysite.com but traffic from WWW.mysite.com comes up as untrusted. I've tried adding www before mysite.com:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*\.)*www.mysite.com$ [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://www.mysite.com/$1 [R]
but it didn't work. Can someone that understands this code please help..
UPDATE: https://mysite.com/ works ok, but mysite.com (without https://) attempts to redirect to https://www.mysite.com/ and comes up with and "untrusted certificate message, this certificate is only valid for mysite.com/" (obvious?) NOTE: mysite.com isn't actually my web site, I've substituted it for my websites name as I can't disclose the address of my own site yet.
Upvotes: 0
Views: 876
Reputation: 66
If I understand your problem correctly, you need to redirect all hits to go to https://mysite.com/ and not to https://www.mysite.com/.
If that is the case, than you have a problem in your last rewrite rule - edit it to be
RewriteRule ^(.*)$ https://mysite.com/$1 [R]
Upvotes: 2
Reputation: 767
This code will redirect all traffic to your site from HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Upvotes: 1