Magento Forum

   
Redirect https to http on non secure pages
 
hereusername
Jr. Member
 
Total Posts:  2
Joined:  2013-03-25
 

Magento has some great built in functionality that if you request a page that should be secure e.g. the checkout via http then it redirects to https. However what seems to be lacking is if somebody requests a page that doesn’t need to be secure e.g. a category page via https then there does not seem to be the functionality to redirect them to http.

So if somebody requests:

https://www.mysite.com/mycategory

they get 301 redirected to

http://www.mysite.com/mycategory

Anybody managed to achieve this?

If not then anybody able to point me in the direction of the bit of the magento core code that does the redirect to HTTPS and then I should be able to work from that to come up with a solution.

My Rewrite-Rules

############################################
## enable rewrites

    Options +FollowSymLinks
    RewriteEngine on

############################################
## you can put here your magento root folder
## path relative to web root

    #RewriteBase /magento/

############################################
## workaround for HTTP authorization
## in CGI environment

    
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

############################################
## always send 404 on missing files in these folders

    
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/

############################################
## never rewrite for existing files, directories and links

    
RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond 
%{REQUEST_FILENAME} !-d
    RewriteCond 
%{REQUEST_FILENAME} !-l

############################################
## rewrite everything else to index.php

    
RewriteRule .* index.php [L]

 
Magento Community Magento Community
Magento Community
Magento Community
 
joshgumballs
Jr. Member
 
Avatar
Total Posts:  6
Joined:  2012-01-17
 

I have run into the same problem, I am not sure that my solution is the most elegant and I would love to figure out how to do it so that the page returns the user to the http version of the page that they requested instead of the home page but here is the code that I added to my htaccess file, the list of exceptions has grown quite large as I found other directories that needed to be exempted:

#Redirect HTTPS to HTTP except checkout and customer account pages 
RewriteCond %{HTTPS} =on
RewriteCond 
%{THE_REQUEST} !^[A-Z]+\s/onestepcheckout|customer|admin|review|sales|newsletter|storecredit|giftcard|supportcenter|skin|dropship|shipworks|checkout|paypal|js|M2ePro|downloader|singlefeed|wp_admin|wp-admin|wp [NC]
RewriteRule 
!^onestepcheckout|customer|admin|review|sales|newsletter|storecredit|giftcard|supportcenter|skin|dropship|shipworks|checkout|paypal|js|M2ePro|downloader|singlefeed|wp_admin|wp-admin|wp http://%{HTTP_HOST} [NC,R=301,L]

Anyone else have a better way to accomplish this

 
Magento Community Magento Community
Magento Community
Magento Community
 
joshgumballs
Jr. Member
 
Avatar
Total Posts:  6
Joined:  2012-01-17
 

Thank you, that worked like a charm.

Josh

 
Magento Community Magento Community
Magento Community
Magento Community
 
paul_po
Jr. Member
 
Total Posts:  2
Joined:  2013-01-02
 

Hi, It works great for me. Thanks a lot.

At the moment, it is having 302(temporary redirect). How to set this to 301 (permanent redirect).

Thanks in advance

 
Magento Community Magento Community
Magento Community
Magento Community
 
paul_po
Jr. Member
 
Total Posts:  2
Joined:  2013-01-02
 

setRedirect($url,301) helped me to set 301 permanent redirect.

Thanks a lot

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top