Redirect all HTTP urls to HTTPS for frontend in magento

Prashant picture Prashant · Jan 27, 2015 · Viewed 17.7k times · Source

I want to redirect all http urls to https in magento, but for front-endonly. In magento we have a setting to use secure urls for front-end as explained in this link: https://www.siteground.com/tutorials/magento/magento_ssl.htm but that applies to only pages shown after login or checkout.

I have applied following code in my .htaccess file:

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]

It is working ok, but it is redirecting Admin panel urls to https as well. I don't want that, I want only front-end to secure not the admin panel urls.

Please check and advise if we can do such thing in magento?

Answer

Sumurai8 picture Sumurai8 · Jan 27, 2015

First remove your rule.

Then, as per this reference go to your admin area. Go to System > Configuration > Web > Secure and turn on the options "Use secure URLS in frontend" and "Use secure URLS in admin".

Links on your website should now all be https. You can use the following rule to redirect people that bookmarked the http-version of your site:

RewriteCond %{HTTPS} off
RewriteRule ^ https://example.com%{REQUEST_URI} [R,L]

Change the R flag to R=301 after testing everything works as expected.