0

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?

2
  • you should just set your insecure url to https. Commented Jun 5, 2015 at 23:56
  • @ReidBlomquist that's the problem. Setting magento's insecure url to https would mean any requests (from google) to http are redirected to homepage on https instead of where they should go.
    – Ash
    Commented Aug 28, 2015 at 8:56

2 Answers 2

6

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]
4

I got this from apache wiki https://wiki.apache.org/httpd/RewriteHTTPToHTTPS

This will enable the Rewrite capabilities
RewriteCond %{HTTPS} !=on

This checks to make sure the connection is not already HTTPS
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.