Symfony routing with and without trailing slashes

UPDATE: Symfony2 version: The Cookbook Routing Redirect URLs with a Trailing Slash.

Symfony routing, by default, seem not work with URLs with trailing slashes.

For example works ok, but results in error 404.

You can fix it easily at application level by overriding sfPatternRouting.

class myPatternRouting extends sfPatternRouting 
  public function parse($url) 
    $url = rtrim($url, '/'); # trim trailing slashes before actual routing
    return parent::parse($url);

Put this code in lib directory in myPatternRouting.class.php file and don’t forget to adjust your settings in factories.yml.

    class: myPatternRouting
      generate_shortest_url: true
      extra_parameters_as_query_string: true

That’s it.

  1. by sobstel • May 2010