8000 [Router] Auto-redirect for trailing slashes fails to match when both routes exist · Issue #36203 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[Router] Auto-redirect for trailing slashes fails to match when both routes exist #36203
Closed
@Seldaek

Description

@Seldaek

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0