re-direct SSL pages using header statement based on port
Posted
by
bob's your brother
on Server Fault
See other posts from Server Fault
or by bob's your brother
Published on 2010-09-01T13:18:36Z
Indexed on
2011/01/11
12:54 UTC
Read the original article
Hit count: 191
I found this in the header.php file of a e-commerce site. Is this better done in a .htaccess file.
Also what would happen to any post parameters that get caught in the header statement.
// flip between secure and non-secure pages
$uri = $_SERVER['REQUEST_URI'];
// move to secure SSL pages if required
if (substr($uri,1,12) == "registration")
{
if($_SERVER['SERVER_PORT'] != 443) {
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
exit();
}
}
// otherwise us regular non-SSL pages
else
{
if($_SERVER['SERVER_PORT'] == 443) {
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
exit();
}
}
© Server Fault or respective owner