Archive

Posts Tagged ‘port’

Redirect HTTPS To HTTP

April 9th, 2009 No comments

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.