Magento: inconsistent URL rewrites

Magento: inconsistent URL rewrites

August 18, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: inconsistent URL rewrites

Magento: Inconsistent URL Rewrites Explained

Hello everyone! I hope you’re doing well out there in the e-commerce world. Today, let’s dive into an issue that seems to be plaguing many of us—inconsistent URL rewrites in Magento 2.

The Strange Behavior of Magento 2 URL Rewrites

First things first, let me set the stage for you:

  1. We have System -> Configuration -> Catalog -> Catalog -> SEO, and we’ve ensured that “Create Permanent Redirect for URLs if URL Key Changed” is set to “No”.
  2. We’ve already tried re-indexing the URL rewrites from the index management panel, but it doesn’t seem to clean up existing mappings.
  3. When we upload a product via a data feed with a blank url_key field, Magento creates its own URL using the product name. For example, a product named “White Shirt A” becomes mydomain.com/white-whirt-a.html.
  4. However, if we delete this product and re-upload the same data feed again, Magento doesn’t remove the previous URL mapping. Instead, it creates a new one with an appended number or ID.

The Three Major Problems

This situation leads to three significant issues:

  1. Creating “Hyphen” Links: We don’t want Magento to create URLs like mydomain.com/white-whirt-a-1.html or mydomain.com/white-whirt-a-1234.html. How can we stop this?

  2. URL Key Mismatch: The url_key field in the admin and catalog export file displays the original URL, like mydomain.com/white-whirt-a.html. But the actual URL is different—why aren’t they matching up?

  3. Product ID as Part of the URL: Sometimes, Magento creates a rewrite that includes the product ID, like mydomain.com/white-whirt-a-1234.html. Under what conditions does this happen?

Let’s Solve These Issues

To start, let me share a snippet from a recent post on our blog at https://laravelcompany.com:

// Example of creating a custom URL key in Magento 2
$product->setUrlKey('white-whirt-a');
$product->save();

This code demonstrates how to set a specific url_key for a product instead of leaving it blank. By doing this, you can ensure that the URL remains consistent.

Best Practices for Managing URLs

Here are some best practices I’d recommend:

  • Always manually set unique and SEO-friendly url_keys when creating or updating products.
  • Regularly clean up your URL rewrites using Magento’s built-in tools or extensions like https://laravelcompany.com/products/url-rewrite-manager (affiliate link).
  • Monitor your site for broken links and redirects to ensure optimal performance.

Wrapping Up

In conclusion, while Magento 2 has some strange quirks with its URL rewrite behavior, there are ways to manage these issues effectively:

  1. Set specific url_keys for each product.
  2. Regularly clean up old or duplicate rewrites.
  3. Monitor your site’s URLs for consistency and performance.

Remember, the key is to stay proactive in managing your Magento store’s URLs. If you have any questions or need further assistance, don’t hesitate to reach out!

Happy coding!

Magento 2 Catalog Indexing Admin

Our network