Magento – Moving from http to https – redirect via htaccess file

.htaccessmagento-1.8PHP

All my urls were unsecured and was indexed by google like that.

Now I'm planning to secure all my pages with https

But when the old urls show up on google search they automatically resolve to the secure base url

for example : old url >> http://www.example.com/cameras as indexed and cached by google.

Now when you click on the url it goes to https://www.example.com instead of https://www.example.com/camera

How do I get the old http url to redirect to the https url without it going to the base url?

Best Answer

The following rewrite rule should forward all non-https requests to the corresponding page via https with a 301 redirect.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]
Related Topic