Symfony2 routing: Allow dots in URL

I have one route in my app that must have a text and a dot followed by a format. For example:

As you can see it’s an url that can contain dots before the dot that splits the {text} and the {_format} parts.


To make this work you have to define the route in routing.yml using a regexp for {text} this way:

    pattern:  /image/{text}.{_format}
    defaults: { _controller: AcmeDemoBundle:Demo:image, _format: png }
        _format: png|jpg
        text: .+


You might also like

Symfony Forms and Bootstrap Datetimepicker
In this example I'm going to use the spanish locale and the "Europe/Madrid" timezone.First we need...

Twig-extensions in Symfony2
Twig comes with multiple filters that provide functions like round, slice, sort, etc. In case you need...

Fix ‘A template that extends another one cannot have a body in …’ in Twig with Symfony2
This may be a confusing error at first but it's quite self explanatory. You can't have any HTML text...

Fix “Cannot redeclare class Symfony…” in Symfony2 after upgrade
After upgrading from Symfony 2.2 to 2.3 I got this error in my application:Fatal error: Cannot redeclare...

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.