I'm trying to force redirect to www with https from index.php but i keep getting an infinite redirect loop.
Here is my code:
index.php:
$configs = include_once($_SERVER['DOCUMENT_ROOT'] . '/application/config/maintenance.php');
if (stripos($_SERVER['SERVER_PROTOCOL'], 'https') === false && $configs['protocol'] == 'https') {
$protocol = 'https://';
$protocolRedirect = true;
} else {
$protocol = 'http://';
$protocolRedirect = false;
}
if (strtolower(substr($_SERVER['HTTP_HOST'], 0, 4)) !== 'www.') {
$url = $protocol . 'www.' . $_SERVER['HTTP_HOST'];
$wwwRedirect = true;
} else {
$url = $protocol . $_SERVER['HTTP_HOST'];
$wwwRedirect = false;
}
if ($_SERVER['REQUEST_URI'] != '/') {
$url .= $_SERVER['REQUEST_URI'];
}
if ((isset($wwwRedirect) && $wwwRedirect == true) || (isset($protocolRedirect) && $protocolRedirect == true )) {
header('Location: ' . $url);
exit();
}
maintenance.php:
return array(
'protocol' => 'https'
);
Any idea why?
Note: server is running Nginx - but i don't want to redirect thorugh it.