Bug #87455

Redirects for root path on Multi-Language page

Added by Deniz Laun 3 months ago. Updated about 2 months ago.

Status:
New
Priority:
Must have
Assignee:
-
Category:
Link Handling, Site Handling & Routing
Target version:
-
Start date:
2019-01-16
Due date:
% Done:

0%

TYPO3 Version:
9
PHP Version:
7.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

I have a multi-lang page configuration with two languages, /de & /en paths.

If I create redirects in the module, I can only create working redirects that match the language.
So /de/test or /en/test.

A non-language-path redirect like /test is redirected directly to the default language - in my case /de.

rootPageId: 1
base: 'https://example.net/'
languages:
  -
    title: Deutsch
    enabled: true
    languageId: '0'
    base: /de
    typo3Language: de
    locale: de_DE.utf-8
    iso-639-1: de
    navigationTitle: Deutsch
    hreflang: de-DE
    direction: ltr
    flag: de
  -
    title: Englisch
    enabled: true
    languageId: '1'
    base: /en
    typo3Language: default
    locale: en_US.utf-8
    iso-639-1: en
    navigationTitle: English
    hreflang: en-US
    direction: ltr
    fallbackType: fallback
    flag: en-us-gb
errorHandling: {  }
baseVariants: {  }
routes:
  -
    route: robots.txt
    type: staticText
    content: "User-agent: *\r\nDisallow: /typo3/\r\nDisallow: /typo3_src/\r\nAllow: /typo3/sysext/frontend/Resources/Public/*\r\n" 

History

#1 Updated by Deniz Laun 3 months ago

I use Typo 9.5.3.
First thought my Bug would be fixed in #86615
It also seems very similiar to #86616

#2 Updated by R3 H6 about 2 months ago

Same problem here. Changing the order of the middlewares is a possible solution...

return [
    'frontend' => [
        'typo3/cms-redirects/redirecthandler' => [
            'disabled' => true,
        ],
        'hotfix-redirecthandler' => [
            'target' => \TYPO3\CMS\Redirects\Http\Middleware\RedirectHandler::class,
            'before' => [
                'typo3/cms-frontend/base-redirect-resolver',
            ],
        ],
    ],
];

Other solution, add a middleware before "typo3/cms-frontend/base-redirect-resolver"

class SetDefaultLanguage implements MiddlewareInterface
{
    /**
     * @param ServerRequestInterface $request
     * @param RequestHandlerInterface $handler
     * @return ResponseInterface
     */
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $site = $request->getAttribute('site', null);
        $language = $request->getAttribute('language', null);

        if ($site instanceof Site && !($language instanceof SiteLanguage)) {
            $language = $site->getDefaultLanguage();
            $request = $request->withAttribute('language', $language);
        }

        return $handler->handle($request);
    }
}

Also available in: Atom PDF