Using .htaccess To Redirect HTTPS To HTTP

To redirect from HTTPS to HTTP on the home page only using the following rule.

RewriteCond %{HTTPS} on
RewriteRule ^/?$ http://%{SERVER_NAME}/ [R=301,L]

The variable %{HTTPS} will be either "on" or "off" and will be enabled even if SSL is not installed on your site. The rule above sees that HTTPS is on and redirects the home page to the HTTP version. You can even chain lots of rules together like this.

RewriteCond %{HTTPS} on
RewriteRule ^/?$ http://%{SERVER_NAME}/ [R=301]
RewriteRule ^inner/directory/?$ http://%{SERVER_NAME}/inner/directory/ [R=301,L]

Note that you should end your last rule with L so that no other rules on the page are run. Also, you need to make absolutely sure that you are not redirecting any pages that are integral to the security of your shopping cart as this will turn off HTTPS for those pages.

You can also do the same thing using the ${SERVER_PORT} variable.

RewriteCond %{SERVER_PORT} 443
RewriteRule ^/?$ http://%{SERVER_NAME}/ [R=301,L]

The port for HTTPS is 443 so if the port being communicated through is 443 we need to redirect.

Comments

hi there,

I am trying to redirect https to http for the website coupon aid
I changed htaccess but it doesn't seem to work. Could you take a look and see what the problem is?

it's not redirecting :(

Permalink

If it isn't redirecting then there are a couple of things you can try. The rules above require mod_rewrite being available on your Apache server, if it isn't on then the rules throw and error. There may be an issue with the expression you are using to redirect if you are trying to do it with an inner directory. Either way, any errors should be logged by your Apache server in the error.log so if nothing works that should point you in the right direction.

Name
Philip Norton
Permalink
What if you use Nginx instead of Apache?
Permalink
I know this is an old thread, but I've just discovered that replacing http with https on my site redirects to a totally unrelated site (shared server). I successfully use htaccess to redirect from mysite.com to www.mysite.com but the above code isn't working.
Permalink
please I need one only htaccess that: for website1 redirect from http to https and for others websites redirect from https to http and please for all websites redirect "without www" to www can you help me? Thanks a lot
Permalink
Here only i learned back-end process of htaccess file. Thank You Genius :)
Permalink

Hello,

RewriteCond %{HTTPS} on

RewriteRule ^/?$ http://%{SERVER_NAME}/ [R=301]

RewriteRule ^inner/directory/?$ http://%{SERVER_NAME}/inner/directory/ [R=301,L]

after using this above code i faced a problem like directory index listing enable and trying to make it disable is not working using htaccess file or other source. 

just i need to redirect HTTPS to HTTP . please provide me a solution for this and also let me how to disable the index listing. 

i used many possible way to redirect or disable index listing is not working..

Permalink

I want to say my website ssl remove & http (S) only how to remove any suggest 

Permalink

I hope this will be helpful for someone

RewriteEngine On

RewriteBase /

# Turn SSL on for /user/login

RewriteCond %{HTTPS} on

RewriteCond %{REQUEST_URI} ^/(yourfilename\.php)$ [NC]

RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

# Turn SSL off everything but /user/login

RewriteCond %{HTTPS} off

RewriteCond %{REQUEST_URI} !^/(yourfilename\.php)$ [NC]

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

 

Permalink

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
2 + 7 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.