We are redirecting all traffic on our Magento CE site to HTTPS URL's by default. This is done by setting both the secure and unsecure base URL to https://domain.com.

We also have the "Auto-redirect to Base URL" set to No because having this option enabled (either 301 or 302) resulted in all requests for http://domain.com/product.html redirecting to the homepage (as per the accepted answer here). So we are forced to have the "Auto-redirect to Base URL" option disabled.

However, with the above setup Magento is doing a 302 redirect for all HTTP requests to the equivalent HTTPS URL. This is great for customers as it works seamlessly, but for search engines we would prefer a 301 redirect.

How can we have it do a 301 redirect instead of a 302 given the setup above?

1 Answer 1


If you've disabled the "Auto-redirect to Base URL" setting, then Magento isn't responsible for the 302 redirect to https. This must be caused elsewhere, most likely in your .htaccess or VirtualHost on your server. That being the case you should just find where this is and change it from 302 to 301.

If you have access to the VirtualHosts you can likely just put the following in the http VirtualHost (likely the one containing *:80 in the declaration.

RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]

If you don't have access to edit the VirtualHost you can put something like this in the .htaccess file.

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://yourdomain.com/$1 [L,R=301]

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.