Description
Symfony version(s) affected: 4.4.x, 5.*
Description
Router auto-redirection for trailing slashes (https://symfony.com/doc/master/routing.html#redirecting-urls-with-trailing-slashes) fails to match the route correctly when both routes (with and without trailing slashes) are defined. In that case, whichever the first route is is matched, and the other redirects to it always.
How to reproduce
Define two routes on a controller
* @Route("/foo", name="foo", defaults={"_format"="json"}, methods={"GET"})
* @Route("/foo/", name="foo_bc", defaults={"_format"="json"}, methods={"GET"})
Accessing /foo works, accessing /foo/ redirects to /foo, even though the exact match route exists. That sounds to me like a bug/overly greediness of the trailing slash redirecter.
Alternative solution or in addition to the bugfix, could be to offer an option for this behavior, which could be configured to either:
- redirect (current)
- allow /foo/ to match a /foo route silently, and /foo to match a /foo/ route also
- no magic, just strict match or 404