From 5f247d4b6025bc761497d4cf908d7f15ae9b7278 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 1 Jun 2022 17:30:54 +0200 Subject: [PATCH] Do not strip the controller in URLs for i18n landing pages MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Previously using an i18n CMS page as the landing page caused very odd behavior as described in commit 0c03edef97240baa6374ce59e986245fb8ffedec. Landing pages naturally cannot contain a language specific custom controller as they don't have a controller within the URL, thus requests to the landing page URL need to be dispatched to one of the languages in ControllerMap::lookupDefaultController(). It was decided to dispatch to the user's current language which certainly is the best solution from the UX perspective. However this dynamic dispatch is problematic, because for i18n landing pages the variant with the default language was also proclaimed to be the default controller in ControllerMap::isDefaultController(), thus stripping it from the language specific custom controller. Ultimately this overloaded accesses to the landing page to both mean “the default language” and “whatever language the user uses” at the same time, unpredictably returning either a HTTP 200 or a HTTP 307 when canonicalizing the URL in CmsPage depending on the user's language, ultimately dropping the landing page from the search index of common search engines when it is crawled in a non-default language. Fix this whole mess by not stripping the controller from the URL for i18n pages, allowing every language, including the default language, to have a stable URL that will always return a HTTP 200 no matter the user's language. The landing page will then dynamically redirect to the user's language, preserving the UX enhancement without any of the drawbacks. --- .../files/lib/system/request/ControllerMap.class.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/wcfsetup/install/files/lib/system/request/ControllerMap.class.php b/wcfsetup/install/files/lib/system/request/ControllerMap.class.php index e98993558c..45fb68d275 100644 --- a/wcfsetup/install/files/lib/system/request/ControllerMap.class.php +++ b/wcfsetup/install/files/lib/system/request/ControllerMap.class.php @@ -5,7 +5,6 @@ namespace wcf\system\request; use wcf\page\CmsPage; use wcf\system\cache\builder\RoutingCacheBuilder; use wcf\system\exception\SystemException; -use wcf\system\language\LanguageFactory; use wcf\system\SingletonFactory; use wcf\system\WCF; use wcf\system\WCFACP; @@ -274,10 +273,7 @@ class ControllerMap extends SingletonFactory if (isset($this->customUrls['lookup'][$application][$controller])) { $controller = $this->customUrls['lookup'][$application][$controller]; if (\preg_match('~^(?P__WCF_CMS__\d+)(?:-(?P\d+))?$~', $controller, $matches)) { - if ( - $matches['languageID'] - && $matches['languageID'] != LanguageFactory::getInstance()->getDefaultLanguageID() - ) { + if ($matches['languageID']) { return false; } -- 2.20.1