-
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
Category::getUrl() should not fetch 301 redirect #38152
Comments
Hi @kweij. Thank you for your report.
Join Magento Community Engineering Slack and ask your questions in #github channel. |
Hi @engcom-Bravo. Thank you for working on this issue.
|
@magento The issue is reproducible on the vanilla Magento instance |
Hi @kweij, Thank you for reporting and collaboration. Verified the issue on Magento 2.4-develop instance and the issue is reproducible.Kindly refer the screenshots. Steps to reproduce
In frontend the category url is changed to new url key but the canonical url is still in old url key. Hence Confirming the issue. Thanks. |
✅ Jira issue https://jira.corp.adobe.com/browse/AC-10464 is successfully created for this GitHub issue. |
✅ Confirmed by @engcom-Bravo. Thank you for verifying the issue. |
Seems to be fixed by ACP2E-2481: Category Canonical URLs not working, so we can close this issue down I guess. |
Hi @kweij, The issue is fixed under this commits : https://github.com/search?q=repo%3Amagento%2Fmagento2+ACP2E-2481&type=commits Hence we are Closing this issue. Thanks. |
Preconditions and environment
Steps to reproduce
URL Key is now auto-generated, system/auto-generated URL Rewrite is created (redirect_type = 0)
System/auto-generated URL Rewrite is updated to a 301 from old to new (redirect_type = 301)
A new system/auto-generated URL Rewrite is added (redirect_type = 0) from new tot internal route
bin/magento config:set catalog/seo/category_canonical_tag 1
State in the database with example data:
Expected result
Canonical URL === New category URL Key
Actual result
Canonical URL === Old category URL Key
Additional information
In
\Magento\Catalog\Model\Category.php::getUrl()
URL rewrites are loaded for the category by ID and store. This returns the first result, which is the 301 redirect from the old to the new category URL. Therequest_path
of this rewrite is used to form the return value ofCategory.php:getUrl()
, which contains the old URL.The fix is that only the system/auto-generated URL rewrite is loaded. Therefor the array param provided to
\Magento\UrlRewrite\Model\UrlFinderInterface::findOneByData()
invendor/magento/module-catalog/Model/Category.php:613
should be extended withUrlRewrite::REDIRECT_TYPE => 0,
. The same addition is already in place for\Magento\Catalog\Model\Product\Url::getProductUrl()
, but missing for categories.Release note
Note that I've only yet encountered this issue in the category canonicals, but since the issue resides in
Category.php:getUrl()
, there are probably other area's where this bug causes an issue.Triage and priority
The text was updated successfully, but these errors were encountered: