8000 [Routing] Route with trailing slash redirects to route without slash · Issue #29438 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Routing] Route with trailing slash redirects to route without slash #29438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
emodric opened this issue Dec 3, 2018 · 8 comments
Closed

[Routing] Route with trailing slash redirects to route without slash #29438

emodric opened this issue Dec 3, 2018 · 8 comments

Comments

@emodric
Copy link
Contributor
emodric commented Dec 3, 2018

Symfony version(s) affected: 4.2.0 and 4.1.8

Description

I have two routes, one without slash, one with the slash, and with 4.2.0 and 4.1.8, there is a redirect from the route with the slash to the route without the slash, causing infinite redirect loop between the two (obviously because the no-slash route redirects back to slash route). #29380 also does not fix the issue.

This works fine on Symfony 4.1.7 and latest 3.4, i.e. no redirect happens from slash route to no-slash route.

How to reproduce

The following routes cause the problem:

test_route_no_slash:
    path: /foo
    methods: [GET]
    defaults:
        _controller: "Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::redirectAction"
        route: test_route
        permanent: true

test_route:
    path: /foo/
    methods: [GET]
    defaults:
        _controller: "App\\Controller\\FooController"

Reproducer is available at https://github.com/emodric/sf_route_redirect_bug

Start the server and open /foo to get the infinite redirects.

@emodric emodric changed the title Infinite redirects between routes with and without slash [Routing] Route with slash redirects to route without slash Dec 3, 2018
@emodric emodric changed the title [Routing] Route with slash redirects to route without slash [Routing] Route with trailing slash redirects to route without slash Dec 3, 2018
@dkarlovi
Copy link
Contributor
dkarlovi commented Dec 3, 2018

@emodric /foo and /foo/ are considered the same when matching since the trailing slash is optional, you basically have the same route defined twice.

@emodric
Copy link
Contributor Author
emodric commented Dec 3, 2018

Hm, wasn't aware of that. However, as I said, this works fine on 4.1.7 and latest 3.4, and it broke in 4.1.8. Shouldn't that be a BC break?

@dkarlovi
Copy link
Contributor
dkarlovi commented Dec 3, 2018

It's actually considered a bugfix, see #29287, #29297.

@emodric
Copy link
Contributor Author
emodric commented Dec 3, 2018

Thanks for the pointers to the previous discussions @dkarlovi.

@nicolas-grekas Should I close this then?

@nicolas-grekas
Copy link
Member

I think yes - at least I don't see how we can "fix" this while preserving the behavior that the linked PRs have also fixed.

@emodric
Copy link
Contributor Author
emodric commented Dec 3, 2018

Okay, no problem. I will have to find an other way to get what I want.

Just for the reference, I used the above routes because of eZ Platform. eZ Platform has a concept of siteaccesses, basically, a set of configuration which is loaded dynamically, based on current request. One of the ways to match which configuration will be loaded is by using an URI part which is injected by eZ before the Symfony path info, thus, it is not part of the Symfony route. So when Symfony redirects the routes from one to the other, that URI part is lost, effectivelly redirecting to the wrong part of the site.

For example: two routes exist: /search and /search/, while /admin is an URI part injected by eZ. So, instead of /admin/search redirecting to /admin/search/, it redirects to /search/, completely loosing the context of the original request.

@emodric emodric closed this as completed Dec 3, 2018
@nicolas-grekas
Copy link
Member
nicolas-grekas commented Dec 3, 2018 via email

@emodric
Copy link
Contributor Author
emodric commented Dec 3, 2018

It works, yes, i tried it already, but then it doesn't work on Symfony 3.4 and 4.1.7 😂

Anyway, I might just remove the redirects altogether, might be easier and less annoying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0