Symfony 4.1 added internationalized routing to allow defining different URLs per locale. In Symfony 5.1 we've improved this feature to also allow different hosts per locale.
In practice, this change means that you can now define an array of values for
the host option. This works both in routes config and when importing groups
of routes. For example, this would define different hosts for English and French
locales in all routes defined as controller annotations:
1 2 3 4 5 6 7
# config/routes/annotations.yaml
controllers:
resource: '../../src/Controller/'
type: annotation
host:
fr: www.example.fr
en: www.example.com
Individual routes can define their own localized host too (and it overrides
any other host config set while importing the routes). Lastly, something to
keep in mind is that when using localized hosts, if a route uses a locale
without a host defined for it, you'll see an exception (there is no default
host value).
Nice addition, thank you :)
Great feature! Thanks Olivier <3
Wow! Nice!
Great, now I can move to symfony5! Thanks!
Yyy ! nice to have this natively, struggled simulating this feature in sf 3 and 4
\o/
super:) What about router.request_context.host in parameter? Is still working? What about url in command line?