From f810a4c19585ac91786bea17f43ed7c0bb2f5d26 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 28 Dec 2016 13:45:21 +0100 Subject: [PATCH] Redirect using 307 on i18n cms language mismatch --- wcfsetup/install/files/lib/page/AbstractPage.class.php | 8 +++++++- wcfsetup/install/files/lib/page/CmsPage.class.php | 5 +++++ .../files/lib/system/request/RequestHandler.class.php | 4 +++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/wcfsetup/install/files/lib/page/AbstractPage.class.php b/wcfsetup/install/files/lib/page/AbstractPage.class.php index adc4ef42c6..ae606776ff 100644 --- a/wcfsetup/install/files/lib/page/AbstractPage.class.php +++ b/wcfsetup/install/files/lib/page/AbstractPage.class.php @@ -47,6 +47,12 @@ abstract class AbstractPage implements IPage { */ public $forceCanonicalURL = false; + /** + * is true if the redirect should use a 307 instead of the default 301, not recommended in general + * @var boolean + */ + public $softRedirectCanonicalURL = false; + /** * indicates if you need to be logged in to access this page * @var boolean @@ -250,7 +256,7 @@ abstract class AbstractPage implements IPage { // force a permanent redirect as recommended by Google // https://support.google.com/webmasters/answer/6033086?hl=en#a_note_about_redirects - HeaderUtil::redirect($redirectURL, true, false); + HeaderUtil::redirect($redirectURL, true, $this->softRedirectCanonicalURL); exit; } } diff --git a/wcfsetup/install/files/lib/page/CmsPage.class.php b/wcfsetup/install/files/lib/page/CmsPage.class.php index 003dfcb6ff..77ff6eefe8 100644 --- a/wcfsetup/install/files/lib/page/CmsPage.class.php +++ b/wcfsetup/install/files/lib/page/CmsPage.class.php @@ -75,6 +75,11 @@ 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; + } + } // update interface language if (!WCF::getUser()->userID && $this->page->isMultilingual && $this->languageID != WCF::getLanguage()->languageID) { diff --git a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php index 446ffe75a1..be36792e7b 100644 --- a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php @@ -155,7 +155,7 @@ class RequestHandler extends SingletonFactory { } // handle CMS page meta data - $metaData = []; + $metaData = ['isDefaultController' => (!empty($routeData['isDefaultController']))]; if (isset($routeData['cmsPageID'])) { $metaData['cms'] = [ 'pageID' => $routeData['cmsPageID'], @@ -243,6 +243,8 @@ class RequestHandler extends SingletonFactory { foreach ($data as $key => $value) { $routeData[$key] = $value; } + + $routeData['isDefaultController'] = true; } /** -- 2.20.1