22

Earlier i have posted this question : https://stackoverflow.com/questions/36104047/how-to-redirect-all-http-requests-to-https-on-magento but didn't get any reaction.

Here is my site URL : www.trendy-mode.nl it will redirect you to : https://www.trendy-mode.nl/

Now problem is menu link or any other sub-links are not redirect with https://

EX:
There is menu like - NIEUW | KLEDING | SCHOENEN | ACCESSOIRES etc.
If you click on NIEUW menu, a new page will be open but not redirect with https://

I have tried a lot .htaccess tweaks but not works. Anybody here to help me on this?

Thank you in advance!

30

Changing the unsecure base url to https will change all links and redirect non-https requests to https://example.com/ (the home page), because that's what Magento does when the base URL validation fails.

So this is a good start but to also redirect http://example.com/foo/ to https://example.com/foo/ you need to do it via webserver redirect.

For example, add the following code at the top of your .htaccess:

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

Or if you use a reverse proxy like Varnish:

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

This is because the requests from Varnish to Magento will be without SSL (HTTP), but Varnish sets the X-Forwarded-Proto header to "https" if the original request was made with SSL (HTTPS).

  • @Abhishek I just tested your site and since it's not working yet - Fabians instructions above are correct .. but should also say that these 2 lines should be added to .htaccess file in the root of your magento installation but NOT at the top (generally) but as mentioned below, just after RewriteEngine On . The way I have done it is just slightly different in that my second line reads; RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] – Peter Svegrup Mar 22 '16 at 17:47
  • Has anyone experienced adverse effects on google page rank after moving a magento site completely to https? – paj Sep 4 '18 at 7:11
10

For completeness we also do a very similar thing to what fschmengler has suggested with some additions;

RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

We place this inside the section of the .htaccess just below RewriteEngine On

9

Set your base url for secure and unsecure in the backend. Set yes on use secure url in frontend in the backend.

Then edit your app/etc/local.xml and include this

<?xml version="1.0"?>
<config>
  <frontend>
     <secure_url>
      <all>/</all>
     </secure_url>
   </frontend>
</config>

Or at least paste the XML tree frontend and lower in between the config tags.

  • This fixed my problem. I had set everything right but some urls were still using http instead of https. – mutiemule Apr 24 '17 at 14:39
  • i want to redirect specif url from https to http. so do you have any idea about it? – Sarfaraj Sipai Apr 26 '18 at 9:50
5

Make sure System > Configuration > Web > url_options > "Auto-redirect to Base URL = No". It was set to yes, and causing the problem.

Put below code in .htaccess file.

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
4

I think the easiest way would be to change the non-secure base url to https since magento then redirects all "non-secure" requests to this url and also generates the links with this url.

you can change the base url under system -> configuration -> general -> web

  • Thank you for your replay.. i did it but now if you open this link : www.trendy-mode.nl/damesschoenen/slippers it will jump you to homepage. have any solution? – Abhishek Kumbhani Mar 20 '16 at 17:19
  • hm thats weird :) Did you mind the trailing slash in the base url? I think this matter is really interesting as it will be most likely beeing seo relevant in the future (or maybe already now?) to have the whole page using https. I can ask my colleague tomorrow since he had done this for a magento shop already – David Verholen Mar 20 '16 at 17:26
  • although fschmengler's solution should work I think, the answer of @Michael seems like the right way to do this if it works – David Verholen Mar 20 '16 at 18:19
  • Well fschmenglers answer is not false. I am just annoyed of Magentos update strategy as it touches .htaccess and index.php but not local.xml. So it's more 'update save' imho – Michael Mar 20 '16 at 21:38
2

The Apache docs recommend against using a rewrite:

To redirect http URLs to https, do the following:

 <VirtualHost *:80>
     ServerName www.example.com
     Redirect / https://www.example.com/
 </VirtualHost>

 <VirtualHost *:443>
     ServerName www.example.com
     # ... SSL configuration goes here
 </VirtualHost>

This snippet should go into main server configuration file, not into .htaccess as asked in the question.

This article might have come up only after the question was asked and answered, but seems to be the current way to go.

0

Add this code at the top of the .htaccess file

RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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