From e83287fd2dfc8ea7883985b0fdc27984c4bd5fd2 Mon Sep 17 00:00:00 2001 From: Tom Rix Date: Mon, 1 Mar 2010 02:53:15 +0000 Subject: [PATCH] BUGFIX: Set absolute domain of 'main site' properly. (from r80951) --- code/SiteTreeSubsites.php | 5 ++++- code/Subsite.php | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/code/SiteTreeSubsites.php b/code/SiteTreeSubsites.php index d8b53c9..bdffb2d 100644 --- a/code/SiteTreeSubsites.php +++ b/code/SiteTreeSubsites.php @@ -224,7 +224,10 @@ class SiteTreeSubsites extends DataObjectDecorator { // Generate the existing absolute URL and replace the domain with the subsite domain. // This helps deal with Link() returning an absolute URL. $url = Director::absoluteURL($this->owner->Link()); - return preg_replace('/\/\/[^\/]+\//', '//' . $this->owner->Subsite()->domain() . '/', $url); + if($this->owner->SubsiteID) { + $url = preg_replace('/\/\/[^\/]+\//', '//' . $this->owner->Subsite()->domain() . '/', $url); + } + return $url; } } diff --git a/code/Subsite.php b/code/Subsite.php index 2910b74..9acd77e 100644 --- a/code/Subsite.php +++ b/code/Subsite.php @@ -114,6 +114,10 @@ class Subsite extends DataObject implements PermissionProvider { $domain = str_replace('.www.','.', $domain); return $domain; } + + // SubsiteID = 0 is often used to refer to the main site, just return $_SERVER['HTTP_HOST'] + } else { + return $_SERVER['HTTP_HOST']; } }