-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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 trailing slash used in url rewrites #10043
Conversation
Hi @ihor-sviziev Please let's implement the logic that you suggested:
|
If request path doesn't match the DB values, if it's redirect (301 or 302) - follow redirect rules from DB results (to have only one redirect); if it's not redirect (category or product page) - redirect to request_path from DB. It will reduce negative effect for SEO and a little bit server load (1 request instead of 2).
Use ternary operators instead of if-else blocks
@ihor-sviziev please let me know when you will be ready for review. thank you |
CC: @redelschaap |
Cover with unit tests
Cover with unit tests
@okorshenko done. Could you review it? I covered it with few tests, you can add or adjust them if needed. |
@ihor-sviziev sure |
From the brief look - it looks good. I will dig deeper into implementation and use cases right now. I would suggest to add integration test for this functionality. Unit test is ok, but integration test will be better in this case. Just create a fixture for URL rewrites and try different requests. |
@ihor-sviziev Looks good. It would be great if you will create integration test to avoid regression on this. Thank you! great job! 👍 Also, please check this test: Magento\Cms\Controller\PageTest . There is some issue with this test after these fixes. For some reason I don't see Travis build for this PR. |
@okorshenko is it possible to cover it with integration tests by someone from magento team? I don't have any experience in writing integration tests. |
@ihor-sviziev Sure. We will take care about this |
- covered changes with integration tests
- fixed integration tests
- added integration tests for CMS pages
@okorshenko thank you for fast processing my PR. These changes not fully backward compatible because they are changing behavior in some cases to redirect, can we add them in 2.1? |
@ihor-sviziev great work man! |
Hi @ihor-sviziev I think yes. If you would like to have this fix in 2.1, just create a PR to 2.1-develop branch and we will try to process it. |
- covered changes with integration tests (cherry picked from commit 0ecf635)
- fixed integration tests (cherry picked from commit 82e5ebe)
- added integration tests for CMS pages (cherry picked from commit 8f031d0)
Description
Admin user configured two URL rewrites in Admin UI. Frontend user may request the page with or without trailing slash. In some case Magento will return 404 page.
We would like to avoid content duplication for the requests with and without trailing slash. If request path has configured url_rewrite (w/ or w/o trailing slash) redirect to this page automatically. If requested path matches configuration, just follow redirect rules.
Fixed Issues (if relevant)
Related pull requests
Implementation Notes
a. if request path is page-one, generate page-one/
b. if request path is page-one/, generate page-one
a. 0 rows - redirect 404 not found
b. 1 row:
- if request path matches the DB value, just follow redirect rules
- if request path does not match the DB value, redirect (301) to request_path from DB results and then the system will work according to b.i scenario
c. 2 rows: use the row that matches user request and follow redirect rules
Contribution checklist