Symfony2 default locale in routing

If someone is interested in, I succeeded to put a prefix on my routing.yml without using other bundles.

So now, thoses URLs work :

www.example.com/
www.example.com//home/
www.example.com/fr/home/
www.example.com/en/home/

Edit your app/config/routing.yml:

ex_example:
    resource: "@ExExampleBundle/Resources/config/routing.yml"
    prefix:   /{_locale}
    requirements:
        _locale: |fr|en # put a pipe "|" first

Then, in you app/config/parameters.yml, you have to set up a locale

parameters:
    locale: en

With this, people can access to your website without enter a specific locale.

Leave a Comment