[BUGFIX] Streamline routing redirects to default site language 46/61346/4
authorOliver Hader <oliver@typo3.org>
Wed, 24 Jul 2019 09:30:44 +0000 (11:30 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 2 Aug 2019 12:03:56 +0000 (14:03 +0200)
Calling the frontend with an URL that does not contain a valid base
URI for a configured language resulted in a temporary redirect (307)
to the base URI of the default language. In order to allow detecting
outdated links returning a page not found (404) is used.

Example: https://example.org/en/ is the base URI of a valid language
+ https://example.org/ -> redirects to default language /en/ (307)
+ https://example.org/nothing/ -> responds a page not found  (404)

Releases: master, 9.5
Resolves: #88838
Change-Id: I9a3eeb53da8e0bb92799d8e29404513699411078
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61346
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Chris Müller <typo3@krue.ml>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Chris Müller <typo3@krue.ml>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/frontend/Classes/Middleware/SiteBaseRedirectResolver.php
typo3/sysext/frontend/Tests/Functional/SiteHandling/SlugSiteRequestTest.php

index 4dbd04e..87e83c5 100644 (file)
@@ -50,8 +50,15 @@ class SiteBaseRedirectResolver implements MiddlewareInterface
         // Usually called when "https://www.example.com" was entered, but all sites have "https://www.example.com/lang-key/"
         // So a redirect to the first possible language is done.
         if ($site instanceof Site && !($language instanceof SiteLanguage)) {
-            $language = $site->getDefaultLanguage();
-            return new RedirectResponse($language->getBase(), 307);
+            if ($routeResult instanceof SiteRouteResult && $routeResult->getTail() === '') {
+                $language = $site->getDefaultLanguage();
+                return new RedirectResponse($language->getBase(), 307);
+            }
+            return GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
+                $request,
+                'The requested page does not exist',
+                ['code' => PageAccessFailureReasons::PAGE_NOT_FOUND]
+            );
         }
 
         // Language is found, and hidden but also not visible to the BE user, this needs to fail
index d822fb2..6314633 100644 (file)
@@ -102,6 +102,7 @@ class SlugSiteRequestTest extends AbstractTestCase
         $domainPaths = [
             'https://website.local/',
             'https://website.local/?',
+            'https://website.local//',
         ];
 
         return $this->wrapInArray(
@@ -141,7 +142,7 @@ class SlugSiteRequestTest extends AbstractTestCase
         $domainPaths = [
             'https://website.local/',
             'https://website.local/?',
-            'https://website.local/welcome',
+            'https://website.local//',
         ];
 
         return $this->wrapInArray(
@@ -253,9 +254,6 @@ class SlugSiteRequestTest extends AbstractTestCase
             $this->buildErrorHandlingConfiguration('Fluid', [404])
         );
 
-        $expectedStatusCode = 307;
-        $expectedHeaders = ['location' => ['https://website.local/en-en/']];
-
         $uri = 'https://website.local/any/invalid/slug';
         $response = $this->executeFrontendRequest(
             new InternalRequest($uri),
@@ -263,18 +261,13 @@ class SlugSiteRequestTest extends AbstractTestCase
         );
 
         static::assertSame(
-            $expectedStatusCode,
+            404,
             $response->getStatusCode()
         );
-        static::assertSame(
-            $expectedHeaders,
-            $response->getHeaders()
-        );
-        // @todo Expected page not found response (404) instead
-        // static::assertContains(
-        //     'message: The requested page does not exist',
-        //    (string)$response->getBody()
-        // );
+        static::assertStringContainsString(
+            'message: The requested page does not exist',
+            (string)$response->getBody()
+        );
     }
     /**
      * @test