Disable forced redirect for i18n landing pages
authorAlexander Ebert <ebert@woltlab.com>
Sun, 8 Jan 2017 21:41:55 +0000 (22:41 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 8 Jan 2017 21:41:55 +0000 (22:41 +0100)
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.

wcfsetup/install/files/lib/page/CmsPage.class.php
wcfsetup/install/files/lib/system/request/ControllerMap.class.php

index 5d6276b2a34caea80803f1f9f2c4b919e12eb794..42f3f75313c2a0a8fd8f5697695f7a1fe8613f98 100644 (file)
@@ -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
index 6ddc1d406719014462d7ef88957697c70f5300df..9feeca63098353624cb405fbcc9ebee0bfc081c9 100644 (file)
@@ -210,9 +210,21 @@ class ControllerMap extends SingletonFactory {
                else if (preg_match('~^__WCF_CMS__(?P<pageID>\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<languageID>\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");
                                }