From: Alexander Ebert Date: Sun, 8 Jan 2017 21:41:55 +0000 (+0100) Subject: Disable forced redirect for i18n landing pages X-Git-Tag: 3.0.0~13 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0c03edef97240baa6374ce59e986245fb8ffedec;p=GitHub%2FWoltLab%2FWCF.git Disable forced redirect for i18n landing pages All though quite nice to automatically redirect visitors to a localized version, it doesn't play well with Google's bot that uses whatever language code it pleases to crawl the page but then wants to crawl everything. --- diff --git a/wcfsetup/install/files/lib/page/CmsPage.class.php b/wcfsetup/install/files/lib/page/CmsPage.class.php index 5d6276b2a3..42f3f75313 100644 --- a/wcfsetup/install/files/lib/page/CmsPage.class.php +++ b/wcfsetup/install/files/lib/page/CmsPage.class.php @@ -76,9 +76,7 @@ class CmsPage extends AbstractPage { $this->canonicalURL = LinkHandler::getInstance()->getCmsLink($this->pageID, $this->languageID); if ($this->page->isMultilingual && RequestHandler::getInstance()->getActiveRequest()->getMetaData()['isDefaultController']) { - if ($this->languageID != LanguageFactory::getInstance()->getDefaultLanguageID()) { - $this->softRedirectCanonicalURL = true; - } + $this->softRedirectCanonicalURL = true; } // update interface language diff --git a/wcfsetup/install/files/lib/system/request/ControllerMap.class.php b/wcfsetup/install/files/lib/system/request/ControllerMap.class.php index 6ddc1d4067..9feeca6309 100644 --- a/wcfsetup/install/files/lib/system/request/ControllerMap.class.php +++ b/wcfsetup/install/files/lib/system/request/ControllerMap.class.php @@ -210,9 +210,21 @@ class ControllerMap extends SingletonFactory { else if (preg_match('~^__WCF_CMS__(?P\d+)$~', $controller, $matches)) { $cmsPageData = $this->lookupCmsPage($matches['pageID'], 0); if ($cmsPageData === null) { - // page is multilingual, use current language id to resolve request - $cmsPageData = $this->lookupCmsPage($matches['pageID'], WCF::getLanguage()->languageID); + // page is multilingual, use the language id that matches the URL + // do *not* use the client language id, Google's bot is stubborn + $languageID = null; + // use a reverse search to find the page + if (isset($this->customUrls['lookup']['wcf']) && isset($this->customUrls['lookup']['wcf']['']) && preg_match('~^__WCF_CMS__\d+\-(?P\d+)$~', $this->customUrls['lookup']['wcf'][''], $match)) { + $languageID = $match['languageID']; + } + + if ($languageID === null) { + // something went wrong, use the current language id + $languageID = WCF::getLanguage()->languageID; + } + + $cmsPageData = $this->lookupCmsPage($matches['pageID'], $languageID); if ($cmsPageData === null) { throw new SystemException("Unable to resolve CMS page"); }