Skip to content

URL routes with or without a trailing slash

by Jean-Marie de Boer on July 26th, 2010

Say you have defined a route like so:

news:
  url:   /news
  param: { module: news, action: index }

This will be matched by http://something.something/news, but not by http://something.something/news/
You might add an additional route with a trailing slash, but you could also simply use this rewrite rule in the .htaccess file:

RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
One Comment
  1. Peter permalink

    I use the following in symfony 2:

    route_name:
    pattern: /:controller{slash}
    defaults: { _controller: bundle:controller:action }
    requirements:
    slash : ‘\/?’

    Hope this is useful. And yes, it creates an unused parameter $slash.

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS