From 0c03edef97240baa6374ce59e986245fb8ffedec Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 8 Jan 2017 22:41:55 +0100 Subject: [PATCH] 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. --- .../install/files/lib/page/CmsPage.class.php | 4 +--- .../lib/system/request/ControllerMap.class.php | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) 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"); } -- 2.20.1