Search code examples
symfonysymfony-3.4symfony-routing

Can't override homepage trailing slash


My site have no "homepage" that use the base url (mydomain.com)
The default routing include the _locale parameter, and thus, fail to match one part of the route depending on how I set it.

Config A

homepage:
    path: /{_locale}/
    defaults:
        _locale: '%locale%'
    requirements:
        _locale: '%locales%'

This first config will match the route homepage with the following URLs

mydomain.com/en
mydomain.com/en/

But will fail to match

mydomain.com
mydomain.com/

Config B

homepage:
    path: /{_locale}
    defaults:
        _locale: '%locale%'
    requirements:
        _locale: '%locales%'

This second config will match the route homepage with the following URLs

mydomain.com
mydomain.com/
mydomain.com/en

But will fail to match

mydomain.com/en/

Any idea what I'm missing in my config to match the 4 possibles URL patterns?


Solution

  • Found my answer:

    homepage:
        path: /{_locale}{trailingSlash}
        defaults:
            _locale: '%locale%'
            trailingSlash: ''
        requirements:
            _locale: '%locales%'
            trailingSlash: /?