Magento uses the url_rewrite table to turn a URL like /women/tops/blue-shirt.html into a product page. On stores with many store views and categories, this table can grow to millions of rows.

Why it matters

  • Every storefront request looks up its URL in this table, so a huge table makes pages slightly slower.
  • Saving a product in the admin becomes slow, because Magento rewrites every one of its URL entries.
  • Reindexing URL rewrites takes much longer.

Find where the rows come from

SELECT entity_type, COUNT(*) FROM url_rewrite GROUP BY entity_type;

Usually product dominates.

Why product rewrites multiply

When Use Categories Path for Product URLs is on, or category product rewrites are generated, Magento creates a URL for every product in every category it belongs to, in every store view. A product in 5 categories across 4 store views gets over 20 rewrites.

How to reduce it

Back up the table first, and read the SEO note below before running this on an established store.

bin/magento config:set catalog/seo/generate_category_product_rewrites 0
bin/magento indexer:reindex catalog_url_rewrite
bin/magento cache:flush

This stops Magento generating a separate rewrite for each category a product is in. Products keep their main URL.

The SEO trade-off

If search engines indexed product URLs that include the category path, those URLs change. Check in Google Search Console which product URLs actually get traffic before you change anything. If category-path URLs rank well, keep the setting and accept a larger table, or plan proper 301 redirects first.

Catch it automatically

MageMonitor checks for this every few minutes as part of its Database checks, and alerts you by email, Slack or webhook the moment it appears, with the exact commands to fix it. See MageMonitor for Magento 2.

Related fixes