Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Routing] Routes with host/locale matrix not working correctly #38209

Copy link
Copy link
Closed
@Wirone

Description

@Wirone
Issue body actions

Symfony version(s) affected: 5.1.5

Description
I've followed #30617 (and symfony/symfony-docs#13571) for configuring support for locales based on host. When I access page through host mapped to non-default locale, page still renders in default locale.

How to reproduce

# config/routes.yaml
foo:
    resource: routes/foo.yaml
    prefix: /
    defaults:
        _format: html
    host:
        en: 'foo.loc'
        pl: 'pl.foo.loc'
# config/routes/foo.yaml
app.foo.landing_page:
    path: /
    methods: [GET]
    controller: App\Foo\LandingPageAction

With config above RedirectableCompiledUrlMatcher has this route collection for this path:

# var/cache/dev/url_matching_routes.php
'/' => [
    [['_route' => 'app.foo.landing_page', '_controller' => 'App\\Foo\\LandingPageAction'], null, ['GET' => 0], null, false, false, null],
    [['_route' => 'app.foo.landing_page', '_controller' => 'App\\Foo\\LandingPageAction', '_locale' => 'en', '_format' => 'html'], 'foo.loc', ['GET' => 0], null, false, false, null],
    [['_route' => 'app.foo.landing_page', '_controller' => 'App\\Foo\\LandingPageAction', '_locale' => 'pl', '_format' => 'html'], 'pl.foo.loc', ['GET' => 0], null, false, false, null],
],

Unfortunately, the first one is matched when I access page via pl.foo.loc, so locale is not set and page displays in default locale.

ℹ️ When I comment out first rule, matching hosts work and locale is set properly.

Maybe I do something wrong but mentioned docs are not merged so support for this feature is somehow undocumented 😉

Possible Solution
Move non-strict rule (without host matching) to the end of the collection for path, so it can run as fallback if other rules (hosts) aren't matched.


CC: @odolbeau

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.