Skip to content

Instantly share code, notes, and snippets.

@bjornbjorn
Last active August 29, 2015 14:11
Show Gist options
  • Save bjornbjorn/b3cb640b97dc85592c3a to your computer and use it in GitHub Desktop.
Save bjornbjorn/b3cb640b97dc85592c3a to your computer and use it in GitHub Desktop.
secure http -> https redirect in master config (EE)
/**
* Force HTTPS on prod & staging. This functionality was previously in the .htaccess'es but we moved
* it here to ease multiple environment development.
*/
if(FORCE_HTTPS && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "")){
$redirect_url = filter_var("https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], FILTER_VALIDATE_URL);
if($redirect_url) {
header("HTTP/1.1 301 Moved Permanently");
header("Location: $redirect_url");
die();
} else {
die('Please use HTTPS equivalent of this URL.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment