Redirect using 307 on i18n cms language mismatch
authorAlexander Ebert <ebert@woltlab.com>
Wed, 28 Dec 2016 12:45:21 +0000 (13:45 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 28 Dec 2016 12:45:29 +0000 (13:45 +0100)
wcfsetup/install/files/lib/page/AbstractPage.class.php
wcfsetup/install/files/lib/page/CmsPage.class.php
wcfsetup/install/files/lib/system/request/RequestHandler.class.php

index adc4ef42c6e85672d3ff678d11d9064ae48f2bc3..ae606776ff1e3e680fcb411e307d47e9d6a31ae4 100644 (file)
@@ -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;
                        }
                }
index 003dfcb6ff528e510524f877256b2d6027491f86..77ff6eefe8104e909ecf8a0109d9460a364b11e7 100644 (file)
@@ -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) {
index 446ffe75a1e29d5936d0e7978245602ec6022561..be36792e7bc90bf82f2d0c0c1d6e23667ea2e04e 100644 (file)
@@ -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;
        }
        
        /**