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']; } }