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:

http://domain.com/image/mi-text-with-dots-.-in-.-the-.-middle.png

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

request-flow

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

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

Ref: http://stackoverflow.com/questions/18098583/error-in-symfony2-when-url-cointains-dot

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...

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...

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

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