This question already has an answer here:

my Magento site redirects all users from http://example.com/foo to https://example.com.

How do I change this to redirect to https://example.com/foo?

I looked at .htaccess in my document root and I can't tell why they're being redirected in the first place. Thanks in advance!

marked as duplicate by Fabian Schmengler, Prince Patel, Siarhey Uchukhlebau, Keyul Shah, Rajeev K Tomy Sep 22 '17 at 19:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Please add more details. Like: Is this an old site? Was this recently installed? What did you do before this happened? Can you access the admin? – fja3omega Sep 20 '17 at 5:31
  • It sounds like your secure url and unsecure base urls are the same in System>Config>General>Web . Can you confirm that? – jscar Sep 20 '17 at 7:32
  • @jscar Yes, the secure url and unsecure base url's are the same. – Tom Sep 21 '17 at 20:35

Ok, in htaccess you should have a mod_rewrite section that starts with <IfModule mod_rewrite.c> Soon after that there should be a line that says RewriteEngine on

After that you need to put the following:

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

Because the secure url and unsecure base urls are the same in Magento admin it is redirecting all traffic to https but it is redirecting traffic to direct URLs to the base URL as you are experiencing. The rule in htaccess will make sure that they are just redirected to the same url but over https.

Please try this on a dev site first.

  • When I put this in .htaccess it worked: RewriteCond %{HTTP:X-Forwarded-Proto} !=https RewriteCond %{HTTPS} !=on RewriteCond %{REQUEST_METHOD} !=POST RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] – Tom Sep 22 '17 at 17:17

In case you are on nginx environment, here is the vhost configuration :

server {

listen 80;
server_name www.test.com test.com;
return 301 https://www.test.com$request_uri;


server {

listen 443 ssl;


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