https

https

Redirect From HTTPS To HTTP Using PHP

If you have a site with parts of it using SSL, but want to turn it off for mundane pages like the blog section then use the following code. This uses the $_SERVER['HTTPS'] variable to see if HTTPS is turned on, if it is then a header is issued and the page redirected.

if ($_SERVER['HTTPS'] == 'on') {
    $url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    header('Location: ' . $url, true, 301);
    exit();
}

You can turn it back on again on your secure pages using the opposite.

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.