Forum Moderators: phranque

Message Too Old, No Replies

http:// to https://

Redirect code to https://

         

pemba76

9:18 am on Jan 11, 2016 (gmt 0)

10+ Year Member



Yesterday I upgraded my domain to SSL.
To migrate from http:// to https:// I used the following code in my .htaccess file:

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com%{REQUEST_URI} [L,R=301,NC]

At the moment this code is serving the purpose for the following:
http://www.example.com -> https://www.example.com
www.example.com -> https://www.example.com
example.com -> https://www.example.com

I also need it to do the following:
https://example.com -> https://www.example.com
But when I type https://example.com, the page just loads as https://example.com without redirecting to https://www.example.com

This can cause duplicate page problem if google indexes both https://example.com and https://www.example.com.

Please help me with the right code to achieve the all the above.

whitespace

9:57 am on Jan 11, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



You just need to add a second condition.... OR host is "example.com"

In other words:


RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} =example.com [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301]

pemba76

12:02 pm on Jan 11, 2016 (gmt 0)

10+ Year Member



Thanks a ton.
Worked perfectly.