New in Symfony 5.1: Different hosts per locale
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
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
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
host defined for it, you'll see an exception (there is no default
New in Symfony 5.1: Different hosts per locale symfony.com/index.php/blog/new-in-symfony-5-1-different-hosts-per-localeTweet this
Become a certified developer! Exams are online and available in all countries.Register Now
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.