ENHANCEMENT Director::forceWWW() now does a 301 redirect for SEO (to be consistent with Director::forceSSL())

MINOR Fix PHP notice in checking $_SERVER['HTTPS']

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63388 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sean Harvey 2008-09-30 03:27:49 +00:00
parent fb1b0b4381
commit 813679cc9b

View File

@ -503,13 +503,14 @@ class Director {
* Force a redirect to a domain starting with "www."
*/
static function forceWWW() {
if(!Director::isDev() && !Director::isTest() && strpos( $_SERVER['SERVER_NAME'], 'www') !== 0 ){
if( $_SERVER['HTTPS'] )
$destURL = str_replace('https://','https://www.',Director::absoluteURL($_SERVER['REQUEST_URI']));
else
$destURL = str_replace('http://','http://www.',Director::absoluteURL($_SERVER['REQUEST_URI']));
if(!Director::isDev() && !Director::isTest() && strpos($_SERVER['SERVER_NAME'], 'www') !== 0) {
if(!empty($_SERVER['HTTPS'])) {
$destURL = str_replace('https://', 'https://www.', Director::absoluteURL($_SERVER['REQUEST_URI']));
} else {
$destURL = str_replace('http://', 'http://www.', Director::absoluteURL($_SERVER['REQUEST_URI']));
}
header("Location: $destURL");
header("Location: $destURL", true, 301);
die("<h1>Your browser is not accepting header redirects</h1><p>Please <a href=\"$destURL\">click here</a>");
}
}