Allow trailing slash for Symfony2 route without params? Allow trailing slash for Symfony2 route without params? symfony symfony

Allow trailing slash for Symfony2 route without params?


I like @Kuchengeschmack's answer (https://stackoverflow.com/a/11078348/593957) because it doesn't trigger external redirects.

Here's a yaml version:

acme_admin_dashboard:    pattern:  /{_locale}/admin{trailingSlash}    defaults: { _controller: AcmeBundle:Admin:dashboard, trailingSlash : "/" }    requirements: { trailingSlash : "[/]{0,1}" }


Just type :

/*** @Route("/route/of/some/page/")*/

so

www.example.com/route/of/some/page 

and

www.example.com/route/of/some/page/

are accepted...


I found a solution to add a trailing slash to a route.

means both link are working www.example.com/route/of/some/page and www.example.com/route/of/some/page/. You can do is this way:

if you route looks like

/** * @Route("/route/of/some/page") */public function pageAction() {

change ist to

/** * @Route("/route/of/some/page{trailingSlash}", requirements={"trailingSlash" = "[/]{0,1}"}, defaults={"trailingSlash" = "/"}) */public function pageAction() {