-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix multilang redirects and routes #3004
base: develop
Are you sure you want to change the base?
Conversation
Multilang redirects and routes were not working due to language prefixes being included in URL when trying to match source URL and redirect/route source pattern. Using `$route` parameter fixes the issue as given route does not include language prefixes (coming from `$uri->path()` in `PagesServiceProvider`). Fixes getgrav#2435.
Note: see issue #2435 for discussion regarding potential shortcomings.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the documentation, this is the correct way to do it. The current code includes the language prefix in the route which is against the docs.
Not only that, but the current logic is also flawed. It checks the given route against the current URL, not the one which you want to dispatch into!
Bumping this :) |
@rhukster Can you confirm my findings? The issue is that the redirect is done based on the CURRENT URL and not the route which was given as a parameter to the method. |
OK, looking into the history of this, the code used to be using |
I can have a poke at that. I take it query parameters are |
I think that the whole concept of having redirect in that method is wrong. Redirecting should be part of routing, not in method that gets a page. I will need to think a bit, but in the mean time there is this in Grav 1.7: It is not being called in this case as there's |
@mahagr Forget what I said, I'm stupid and forgot that redirects work when using the workaround stated in #2435 (prefixing with |
You are right, looks like configuration redirects still happen and are wrong, even when you're using |
The above pull request will not fix the language redirects needing the language code, but will only separate the logic between For the language codes, I still think that However it could be a good idea to be able to pass more information to the redirects, such as The reason why I'd like to do it in that way is that you do not want to restrict redirects to Grav routes as you may have migrated from another CMS. |
@mahagr Revisiting old PRs -- I see there was some work on this via #3266. If you have some additional thoughts on how to advance this further I am open for taking a jab at it. The workaround outlined above has been working fine forever, but still think it would be nice to have it work as intended by the documentation (or fix the documentation, which I can also do if we think that's better). |
Multilang redirects and routes were not working as per the documentation ("All redirect rules apply on the slug-path beginning after the language part (if you use multi-language pages)") due to language prefixes being included in URL when trying to match source URL and redirect/route source pattern.
Using
$route
parameter fixes the issue as given route does not include language prefixes (coming from$uri->path()
inPagesServiceProvider
).Fixes #2435.