I am working with non-profit on an application that was built by someone else earlier this year. The site needs to be secure, so I worked with their host to get a SSL cert installed. I understand that updating the .htaccess server file would be easier to perform the redirect, but our engagement ends in about 3 weeks. It has been difficult getting the requirements fed through the non-profit customer contact to host company. As an alternative, I would like to have a php based redirect in place just in case.
This is the beginning section on the apps header page included on all pages. We have 3 test servers with different domains and a production domain. I have added a condition so the redirect will not occur when running locally. When I call the function with my condition causes a redirect loop on the test servers (they have SSL certs). Can someone help with what I can not quite figure out? Thanks.
Or does any know if the apache .htaccess file can be updated as a customer user with Dreamhost?
<?php
function redirectToHTTPS() {
if($_SERVER['HTTPS']!="on") {
$redirect= "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header("Location:$redirect");
}
}
$serverList = array('localhost', '127.0.0.1');
if(!in_array($_SERVER['HTTP_HOST'], $serverList)) {
redirectToHTTPS();
}
ob_start();
include ($_SERVER['DOCUMENT_ROOT'].'/rmhcOmahaTeam/config/paths.php');
include ($_SERVER['DOCUMENT_ROOT'].'/rmhcOmahaTeam/config/db_connect.php');
?>