magento2: Moving a category to a new parent does not generate 301 redirects for product URLs

Preconditions and environment

  • Magento 2.4.6 and potentially all prior versions

Steps to reproduce

  1. Install any recent version of Magento (2.4.4 - 2.4.6)
  2. Enable the following settings under Catalog -> Catalog -> SEO Screenshot 2023-03-08 at 1 16 39 PM
  3. Create two categories under the root category with one child category under the first one.
  4. Create a product and assign it to the child category.
  5. Enable all categories and products.
  6. Using the drag & drop feature of the category tree, move the child category to be underneath the second parent you created.
  7. Navigate to Marketing -> URL Rewrites, and observe that a 301 redirect was created for the original category URL, but not for the original product URL within the original parent category.

Expected result

A 301 redirect will be created for every category / product URL path within the original parent category pointing to the new category / product path under the new parent category. Frontend visitors will get redirected to the new product URL path if they try to access the original path.

Actual result

A 301 redirect was created from the old category path to the new one, but no redirects were created for product URLs. Frontend visitors receive a 404 if they try to access the original product URL path.

Additional information

The issue appears to lie in this observer Magento\CatalogUrlRewrite\Observer\CategoryProcessUrlRewriteMovingObserver. It calls this method $this->urlRewriteHandler->deleteCategoryRewritesForChildren($category), which results in the product level rewrites being deleted before this method is run $productUrlRewriteResult = $this->urlRewriteHandler->generateProductUrlRewrites($category), which looks for those rewrites for the purpose of creating 301 redirects.

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 5
  • Comments: 26 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Hi @hiddenmike. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:


Join Magento Community Engineering Slack and ask your questions in #github channel. ⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. 🕙 You can find the schedule on the Magento Community Calendar page. 📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.