Search code examples
symfonyroutesescapingsymfony-2.3

Hash escape in URL (routing.yml/path) Symfony 2


I have problem with urls in my Symfony 2.3 aplication.

I have defined routing like this:

home_how_to_buy:
path:    /strefa-wiedzy#jak-kupic
defaults: 
  _controller: FrameworkBundle:Template:template
  template: 'GLHomeBundle:Default:faq.html.twig'

The problem is that when I create links for this page I have something like:

app_dev.php/strefa-wiedzy%23jak-kupic

I have been looking for escaping in yml files, but none of those solutions work for my path. I will be gratefull for any help.


Solution

  • As stated in my answer here the hashtag is not intended to be in symfony routing. You can do the suggested workaround. But first you should consider, do you really need url-fragments in routing?

    PHP's rawurlencode() encodes all chars except a-zA-Z0-9-._~ according to RFC 3986. But we want to allow some chars to be used in their literal form (reasons below). Other chars inside the path must of course be encoded, e.g. ? and # (would be interpreted wrongly as query and fragment identifier), ' and " (are used as delimiters in HTML).