Tag Archives: dot

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