From e5f39820586313943671efa5625586a25fed8221 Mon Sep 17 00:00:00 2001 From: Andrew O'Neil Date: Wed, 8 Oct 2008 22:53:20 +0000 Subject: [PATCH] BGFIX: #2587 Fix HTTPS detection on IIS (mackeyn) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63912 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/HTTP.php | 2 +- core/control/Director.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/HTTP.php b/core/HTTP.php index da5bda927..a683c812d 100644 --- a/core/HTTP.php +++ b/core/HTTP.php @@ -26,7 +26,7 @@ class HTTP { $urlBase = substr($_SERVER['PHP_SELF'], 0, -(strlen($_SERVER['SCRIPT_FILENAME']) - $commonLength)); $url = $urlBase . substr($filename, $commonLength); - $protocol = $_SERVER['HTTPS'] ? "https" : "http"; + $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? "https" : "http"; return "$protocol://". $_SERVER['HTTP_HOST'] . $url; // Count the number of extra folders the script is in. diff --git a/core/control/Director.php b/core/control/Director.php index aa7b69304..49e9acbc4 100644 --- a/core/control/Director.php +++ b/core/control/Director.php @@ -304,7 +304,7 @@ class Director { } } - $s = (isset($_SERVER['SSL']) || isset($_SERVER['HTTPS'])) ? 's' : ''; + $s = (isset($_SERVER['SSL']) || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')) ? 's' : ''; if(isset($_SERVER['HTTP_HOST'])) { return "http$s://" . $_SERVER['HTTP_HOST']; @@ -511,7 +511,7 @@ class Director { * */ static function forceSSL() { - if(!isset($_SERVER['HTTPS']) && !Director::isDev()) { + if((!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && !Director::isDev()) { $destURL = str_replace('http:', 'https:', Director::absoluteURL($_SERVER['REQUEST_URI'])); header("Location: $destURL", true, 301); @@ -524,7 +524,7 @@ class Director { */ static function forceWWW() { if(!Director::isDev() && !Director::isTest() && strpos($_SERVER['SERVER_NAME'], 'www') !== 0) { - if(!empty($_SERVER['HTTPS'])) { + if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { $destURL = str_replace('https://', 'https://www.', Director::absoluteURL($_SERVER['REQUEST_URI'])); } else { $destURL = str_replace('http://', 'http://www.', Director::absoluteURL($_SERVER['REQUEST_URI']));