Last Updated: February 25, 2016
· craigmarvelley

Symfony2: Redirecting a root path to that of a default locale.

While working on a Symfony2 application which uses locale prefixing of URLs to support a multilingual site, I wanted to redirect the root URL ( to that of my default locale (

This can be done quite simply with routing configuration, which I learned from this cookbook article. Using the standard container parameter 'locale', which sets a default locale, we can also embed the locale value dynamically:

    pattern: /
        _controller: FrameworkBundle:Redirect:urlRedirect
        path: /%locale%/
        permanent: true

Adding the above to my app/config/routing.yml file was all I needed to make /en/ the default path of my site.

2 Responses
Add your response

Thanks for the simple fix!

over 1 year ago ·


over 1 year ago ·