Here it is in PHP as you wish: ( reply edited by @Bacco)
<?php
function ForceHTTP() {
if ($_SERVER['HTTPS'] == "on") {
$url = $_SERVER['SERVER_NAME'];
$new_url = "http://" . $url . $_SERVER['REQUEST_URI'];
header("Location: $new_url");
exit;
}
}
?>
Don’t forget to "call" the function:
<?php ForceHTTP(); ?>
Or with .htaccess
to always open in HTTP://
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Or with .htaccess
to always open in HTTPS://
(which is how I use on my website):
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Try with this rule, make sure that
mod_rewrite
is enabled.– Lucio
Remembering that anyway, there will be an initial error, because the negotiation of SSL (the secure connection of https) will occur before the HTTP request itself, therefore, before the redirect. This is why each site with SSL usually needs a separate IP for each domain, while the HTTP 426 method is not common for hosting. (this number I memorized, reminds me of LV-426 :P )
– Bacco
Usually the hosts that are shared use shared ssl, as it comes out much more into account.
– the flash