Get free audit

Magento URL Rewrites: Fix Duplicate URLs, -1 Suffixes and Table Bloat

Magento URL rewrites: how the url_rewrite table causes duplicate URLs, -1 suffixes and table bloat

Magento stores every product, category and CMS page URL, and every redirect between them, as rows in one database table called url_rewrite. Each row maps a public request path to an internal route for one store view. Most Magento duplicate URLs, unexplained -1 URL keys and lost redirects trace back to how that table is filled, emptied and regenerated.

Setting defaults below are checked at Magento Open Source release tags from 2.3.3 to 2.4.9. Behaviour is checked in the 2.4.9 source unless another version is named, and against Adobe’s documentation where Adobe documents it.

The short version:

  • Check Generate “category/product” URL Rewrites first. It defaults to Yes up to 2.4.5-p1 and to No from 2.4.6, and saving it as No permanently deletes rows.
  • Turn on canonical tags for products and categories. Both default to No.
  • In core Magento, a -1 URL key comes from Save & Duplicate, not from imports.
  • Before deleting anything, export the 301 rows that carry links or traffic.
  • Never truncate the table. A reindex does not rebuild it.

What a URL rewrite is in Magento

A URL rewrite is a row in url_rewrite that tells Magento which internal route to serve for a public URL. When a shopper requests blue-dress.html, the router looks up that path for the current store view and finds the target catalog/product/view/id/42.

Diagram of a Magento URL rewrite: the request path blue-dress.html is looked up in the url_rewrite table and served from the target path catalog/product/view/id/42
One row in url_rewrite maps the public URL to the internal route Magento serves.

The redirect type decides what happens next. A value of 0 is a true rewrite: Magento serves the target and the address bar keeps the friendly URL. A value of 301 or 302 sends the browser to the target path instead.

ColumnWhat it holdsWhy it matters for SEO
request_pathThe public path, such as women/dresses/blue-dress.htmlThe URL Google crawls
target_pathThe internal route, or a redirect’s destinationWhat the URL serves or where it redirects
redirect_type0 rewrite, 301 permanent, 302 temporarySeparates live URLs from redirects
store_idThe store view the row belongs toEach store view has its own rows
entity_typeproduct, category, cms-page or customShows what created the row
is_autogenerated1 for system rows, 0 for custom rows and 301 historyDecides which rows Magento may delete itself
metadata{"category_id":"N"} on category-path product rowsMarks the rows behind category-path duplicates

A unique key on request_path and store_id means a path can exist only once per store view. That constraint is the source of the “URL key for specified store already exists” error.

System rewrites, custom rewrites and 301 history

Magento writes system rows, with is_autogenerated = 1, whenever a product, category or CMS page is saved or imported. A 301 written after a URL key change gets is_autogenerated = 0, the same flag as a rewrite added by hand. Magento therefore treats its redirect history and your custom redirects alike, which matters when a setting deletes only autogenerated rows.

Creating a custom 301 in the admin

Go to Marketing > SEO & Search > URL Rewrites and click Add URL Rewrite. Choose Custom, For Category, For Product or For CMS page; the type can’t be changed later. Pick the store view, enter the request and target paths, and set Redirect Type to Permanent (301). The grid shows ID, Store View, Request Path, Target Path and Redirect Type, with no export button and no entity type filter, so audits need SQL.

The settings that decide which URLs exist

These settings control what Magento writes to url_rewrite and which URL it links to. All but the first sit under Stores > Settings > Configuration > Catalog > Catalog > Search Engine Optimization; Use Web Server Rewrites sits under General > Web. The wider admin setup is covered in Magento SEO best practices.

SettingConfig pathDefaultRecommended
Use Web Server Rewritesweb/seo/use_rewritesNo in core config; the installer’s --use-rewrites option sets itYes. No adds index.php/ to URLs
Product and Category URL Suffixcatalog/seo/product_url_suffix, category_url_suffix.htmlKeep the current one
Use Categories Path for Product URLscatalog/seo/product_use_categoriesNoNo
Create Permanent Redirect for URLs if URL Key Changedcatalog/seo/save_rewrites_historyYesYes
Generate “category/product” URL Rewritescatalog/seo/generate_category_product_rewritesYes from 2.3.3 to 2.4.5-p1, No from 2.4.6No, after the export below
Product URL Rewrite Scopecatalog/seo/product_rewrite_contextStore View (new in 2.4.8)Store View
Apply transliteration for product URLcatalog/seo/product_url_transliterationYes (new in 2.4.8)Yes on Latin-script stores
Use Canonical Link Meta Tag For Productscatalog/seo/product_canonical_tagNoYes
Use Canonical Link Meta Tag For Categoriescatalog/seo/category_canonical_tagNoYes

Use Categories Path for Product URLs

This setting controls which product URL Magento links to, not which rows it generates. Set to No, links use the short blue-dress.html. Before 2.4.6, though, Magento still generated rows such as women/dresses/blue-dress.html by default. Those URLs return the product with a 200 status although nothing links to them, which makes them the most common duplicate on upgraded stores.

Generate “category/product” URL Rewrites

This global setting decides whether Magento writes category-path rows for products at all. It arrived in 2.3.3, defaulted to Yes through 2.4.5-p1 and defaults to No from 2.4.6. Adobe’s backward-incompatible changes page says the new default “does not change existing records” and “no new rewrites are added.” An upgraded store keeps its old value; a fresh 2.4.6 install starts at No. The change was missing from the 2.4.6 release notes, as GitHub issue #37772 records.

Timeline of the Generate category/product URL Rewrites default in Magento: Yes from 2.3.3 to 2.4.5-p1, No from 2.4.6
The default flipped at 2.4.6. An upgraded store keeps whatever value it already had.

Saving it as No deletes rows. In the Magento source, the field deletes every autogenerated product row whose metadata starts with {"category_id", on an admin save and on bin/magento config:set alike. Adobe’s automatic redirects documentation warns the removal “cannot be restored.” Adobe’s backward-incompatible changes page describes the deletion against the value 1; the code deletes on 0.

Category-path 301 history survives that delete, but only until each product’s rows are next regenerated. With the setting on No, the next URL key, website or visibility change on a product drops its old category-path 301s. The safe order on an upgraded store is to export category-path URLs with links or traffic, re-create them as Custom 301s, then save No. Custom rows are untouched by both deletions. On 2.4.7, category-path rows were still generated with the setting off; GitHub issue #39070 confirms the bug, fixed in 2.4.8.

One exception: if the store deliberately links category-path product URLs, those rows are the live URLs. Saving No would turn them into 404s, so leave it on Yes until the URL structure has been migrated.

Create Permanent Redirect for URLs if URL Key Changed

On by default, this setting pre-ticks the Create Permanent Redirect for old URL checkbox on product and category edit screens, so a URL key change writes a 301 from the old path. In the 2.4.9 source, the product generator overrides the checkbox with the store setting, so clearing it no longer stops the 301. GitHub issue #41825 reproduces this on a clean 2.4.9 install and reports that 2.4.8-p5 behaves correctly. Category moves always follow the store setting.

Product URL Rewrite Scope and transliteration (2.4.8)

Product URL Rewrite Scope offers Store View, the default, or Website, which generates rows for every store view in the store group when a product is edited. Apply transliteration for product URL, on by default, reduces a URL key to letters, numbers and hyphens. Turned off, it only replaces spaces and lowercases, so non-Latin characters and dots survive.

How rewrites multiply in the url_rewrite table

In the Magento source, a product gets one row for its short URL in every store view where it is visible. With Generate “category/product” on Yes, it also gets a row per assigned category and per anchor category above it, again per store view. 301 history adds more over time. An illustrative example, for one product in Men > Tops > Jackets with all three categories set as anchors, in three store views:

Diagram comparing url_rewrite rows for one Magento product in three store views: 12 rows with Generate category/product URL Rewrites on Yes, 3 rows with it on No
One product, three categories, three store views: 12 rows with the setting on Yes, 3 with it on No.
SettingPaths per store viewRows, 3 store views
Generate “category/product” = Yesjacket.html, men/tops/jackets/jacket.html, men/jacket.html, men/tops/jacket.html12
Generate “category/product” = Nojacket.html3

Category changes cascade. A new category URL key, or a category move, regenerates the category, its children and, with the setting on Yes, every product row underneath. In GitHub issue #7874 the reporter describes 140,000 products, one category holding over 40,000, and category saves running out of memory. Imports work the same way: Adobe’s import documentation advises leaving out the url_key and categories columns when they aren’t changing, because either one regenerates rewrites for every product in the file.

No published “healthy” size exists. Adobe’s knowledge base says table size “does not directly affect the site performance” and flags tables of 1 GB and more for write performance. A better check compares the actual row count with what the code predicts: visible products, categories and CMS pages, each multiplied by store views, plus 301 history. A large excess points to category-path rows or old history.

The duplicate URLs Google finds

Four patterns produce most rewrite-related duplicate and stray URLs.

Category-path product URLs

Rows generated under the old default let women/dresses/blue-dress.html serve the same page as blue-dress.html. Magento outputs no canonical tag by default, so nothing tells Google which to choose. With product canonicals on, the Magento product canonical tag names the URL without the category, so every category-path URL points to the short URL. In the Search Console Pages report, these URLs typically sit under “Duplicate without user-selected canonical” before the fix and “Alternate page with proper canonical tag” after it. Turn the canonical on first, then 301 the category-path URLs with links and remove the rest through the setting.

Diagram of a Magento product served at both a category-path URL and its short URL, with the canonical tag pointing the category-path URL to the short one
Two URLs serve one product. With product canonicals on, the category-path URL points to the short one.

catalog/product/view/id URLs

Magento links to catalog/product/view/id/N when a product has no rewrite row for the store view, usually after a failed import or a switch back from Not Visible Individually. In the Magento source, the ID URL renders with a 200 status if the product is enabled and visible, returns 404 otherwise, and never redirects to the friendly URL.

The XML sitemap repeats the mistake. It reads product URLs from url_rewrite, and when a product has no row it writes the ID URL instead; categories fall back to catalog/category/view/id/N the same way. Fix the missing row, then check that the sitemap lists no ID URLs. Re-saving a product rebuilds its missing rows.

Store-view URL keys

Unticking Use Default Value on a URL key gives that store view its own paths. Imports have a record of mishandling these overrides, and issues such as #41417 are still open, so check store-view keys before any bulk change.

index.php and .html.html URLs

With Use Web Server Rewrites on No, Magento adds index.php/ to URLs. Double suffixes such as dress.html.html are reported mainly after Magento 1 migrations, where the URL key already ended in .html. Transliteration turns that dot into a hyphen, but on 2.4.8 or later with transliteration off, a dotted key survives.

Rewrites are not the biggest source of duplicates on most catalogues; layered navigation filter URLs are, and they need different controls. For both, Google’s guide to consolidating duplicate URLs is direct: “Don’t use the robots.txt file for canonicalization purposes.” Redirects and rel="canonical" are the strong signals.

Why Magento adds -1 to a URL key

In core Magento, a -1 URL key comes from Save & Duplicate. The product copier appends -1, or raises an existing trailing number, so duplicating blue-shirt-1 gives blue-shirt-2. It also sets the copy to Disabled and clears its meta title, keywords and description. No other code in the 2.4.9 catalogue, import or URL rewrite modules numbers URL keys. One side effect of the pattern: a key that legitimately ends in a number, such as calendar-2024, becomes calendar-2025 on a duplicate.

Diagram of Magento Save and Duplicate numbering URL keys: blue-shirt is copied to blue-shirt-1, and that copy to blue-shirt-2
Save & Duplicate appends -1 to the URL key, or raises a number that is already there.

The copy starts disabled, so it returns 404 and stays out of the sitemap. The leak comes later, when someone enables it with the -1 key and an empty meta title. Make it a rule to give a duplicated product a descriptive URL key and meta title before enabling it.

For -1 URLs already indexed, rename and 301 only when the key misleads, such as blue-dress-1 on a red dress. Google’s ecommerce URL guidance notes that “The words in URLs may help Google better understand the page.” If the page is distinct and already ranks or has links, leave it alone; a rename costs a re-crawl.

Imports and “URL key for specified store already exists”

Core imports never add a suffix. A duplicate key stops the row with “Url key: ‘%s’ was already generated for an item with the SKU: ‘%s’. You need to specify the unique URL key manually.” Numbered keys that arrive with an import come from the source file or a third-party importer.

“URL key for specified store already exists” means the new request path is already taken in that store view, by another product, a category, a CMS page or an old 301. GitHub issue #12412, open since 2017, shows Save & Duplicate failing this way when the numbered key is free as an attribute but already used as a request path.

Redirect history and redirect chains

With the redirect setting on, a URL key change writes a 301 from the old path to the new one. On every later regeneration, Magento re-points existing product and category 301s at the current URL. A key changed from A to B to C is stored as A to C and B to C, not as a chain.

Diagram of Magento redirect history after a URL key changes from A to B to C: both old keys are stored as direct 301 redirects to C, not as a chain
Magento re-points old 301s at the current URL, so two key changes do not make a chain.

Chains come from two other places. Custom rewrites are never re-pointed, so a custom 301 aimed at a path that later moved becomes a two-hop chain. Server and CDN rules, such as HTTP to HTTPS, add another hop in front of Magento’s own.

Google’s guidance on moving URLs says Googlebot can follow up to 10 hops, but advises “redirecting to the final destination directly,” ideally with no more than 3 hops and fewer than 5. It also says to keep redirects “generally at least 1 year.” A URL key change costs nothing when the 301 is written and kept.

Changes that remove a URL without a 301

Several routine admin actions delete rewrite rows outright, so the old URL returns 404 with no redirect. These are behaviours of the 2.4.9 source:

ActionWhat happens in url_rewrite
CMS page URL key changedThe page’s rows are replaced; core never writes a 301 for CMS pages
Product set to Not Visible IndividuallyAll its rows for those store views are deleted, 301 history included
Product deletedAll its rows are deleted, 301 history included
Category deletedIts rows, its children’s rows and their category-path product rows are deleted
Product removed from a categoryThat category’s path rows and 301s are dropped at the next regeneration
URL key changed by CSV importA 301 is written only if the file has a save_rewrites_history column set to 1
Generate “category/product” saved as NoCategory-path rows go at once; their 301s go product by product

Disabling is different: a disabled product keeps its rows but returns 404, as does a disabled category. Stock status plays no part, so an out-of-stock product keeps its URL.

Before any of these changes, export the affected request paths, check which have links or organic landings, and add Custom 301s afterwards to the closest equivalent page. Google warns that sending many old URLs to “one irrelevant single URL destination, such as the home page” might be treated as a soft 404. With no equivalent, a 404 is the honest answer.

How to audit your URL rewrites

A rewrite audit reads four sources. The database shows what Magento can serve, a crawl shows what the store links to, Search Console shows what Google chose, and logs show what Googlebot requested. Run one after every upgrade, after imports that touch url_key or categories, after a category restructure and when a store view is added.

Diagram of the four sources a Magento URL rewrite audit reads: the database, a crawl, Search Console and server logs
Four sources, four different answers. A rewrite audit reads all of them.

The queries below are read-only and checked against the 2.4.9 schema. Run them on a replica or with a read-only user, and add the table prefix if the store has one. Start with the stored settings, where a missing row means the default applies:

SELECT path, scope, scope_id, value
FROM core_config_data
WHERE path LIKE 'catalog/seo/%'
   OR path = 'web/seo/use_rewrites';

Break the table down by type, store view and redirect type. This scans the whole table, so run it once, off-peak:

SELECT entity_type, store_id, redirect_type, is_autogenerated,
       COUNT(*) AS row_count
FROM url_rewrite
GROUP BY entity_type, store_id, redirect_type, is_autogenerated;

Count category-path product rows, split into system rows and 301 history:

SELECT store_id, is_autogenerated, redirect_type,
       COUNT(*) AS row_count
FROM url_rewrite
WHERE entity_type = 'product'
  AND metadata LIKE '{"category\_id"%'
GROUP BY store_id, is_autogenerated, redirect_type;

Count live product URLs with a numbered key. Some will be genuine sizes or years, so sample a few before acting:

SELECT store_id, COUNT(*) AS numbered_keys
FROM url_rewrite
WHERE entity_type = 'product'
  AND redirect_type = 0
  AND metadata IS NULL
  AND request_path REGEXP '-[0-9]+([.][a-z]+)?$'
GROUP BY store_id;

Find chain candidates, where a redirect points at a path that is itself redirected:

SELECT a.entity_type, COUNT(*) AS chain_candidates
FROM url_rewrite a
JOIN url_rewrite b
  ON b.request_path = a.target_path
 AND b.store_id = a.store_id
WHERE a.redirect_type IN (301, 302)
  AND b.redirect_type IN (301, 302)
GROUP BY a.entity_type;

Outside the database:

  • Sitemap: the count of catalog/product/view and catalog/category/view URLs should be zero.
  • Crawl: flag ID URLs, category-path product URLs, numbered keys, chains and index.php/ URLs.
  • Search Console: read “Duplicate without user-selected canonical”, “Alternate page with proper canonical tag”, “Page with redirect” and “Not found (404)” in the Pages report, and compare user-declared and Google-selected canonicals in URL Inspection.
  • Logs: count Googlebot requests and status codes for the same patterns, verifying the bot by reverse DNS.

How to clean up the table without losing rankings

Never truncate url_rewrite. It removes every friendly URL and every 301 at once, and core Magento has no command to rebuild them. A safe cleanup keeps what carries value in a form Magento won’t delete, then removes the rest in stages.

Rows to keep

Keep every 301 whose old path has external links, organic landings in the last 12 to 16 months, or Googlebot hits in the logs. Export the candidates first:

SELECT store_id, entity_type, request_path, target_path
FROM url_rewrite
WHERE redirect_type = 301
ORDER BY store_id, entity_type;

Match it against a backlink export, Search Console Performance data and the logs. Re-create the keepers as Custom 301s to the final URL; custom rows survive both the setting’s delete and product regeneration.

Rows you can remove

Unlinked category-path product rows can go, removed by saving Generate “category/product” as No rather than by a hand-written delete. Rows for store views that no longer exist can go once a SELECT confirms them. Change one row type per release, so any movement in Search Console has one cause.

  1. Back up url_rewrite and catalog_url_rewrite_product_category.
  2. Run the change on a staging copy and compare row counts and sample URLs.
  3. Create the Custom 301s from the keep-list.
  4. Apply the change in production, off-peak.
  5. Watch 404s in the logs and the Pages report daily for a week, then weekly for four to six weeks.

Google says moved URLs can take “a few weeks or more” to settle on medium-sized sites, so judge the result on that timescale and keep the backup until it has.

Regenerating URL rewrites

Core Magento has no command to regenerate URL rewrites, a gap open as a feature request in GitHub issue #29629 since 2020. bin/magento indexer:reindex does not help, because the URL rewrite module has no indexer. Rows are written by save events instead: when an entity is saved or imported, when a category moves and when a store view is created in the admin.

For a few products, re-saving is enough: Magento rebuilds rows for any store view where a visible product has none. For bulk work, open-source command-line tools fill the gap: n98-magerun2’s sys:url:regenerate, olegkoval’s ok:urlrewrites:regenerate with a dry-run option, and the elgentos regenerate:product:url and regenerate:category:url commands. Regenerate categories before products, back up first and test on staging. Core also has no CSV import or export for url_rewrite.

URL rewrites on Adobe Commerce as a Cloud Service and headless storefronts

Adobe Commerce as a Cloud Service with an Edge Delivery Services storefront does not route through the admin rewrite table. Adobe’s storefront SEO documentation states that “PaaS URL rewrites (Marketing > SEO & Search > URL Rewrites) don’t transfer automatically.” Active ones go into a redirect spreadsheet named redirects, with Source and Destination columns and no wildcards. Product URLs default to /products/{urlKey}/{sku}. The 301 export above is the starting list, and it belongs in the wider redirect map covered under Magento migration and upgrade SEO.

Headless storefronts read rewrites through the GraphQL route query, which returns a redirect_code of 0, 301 or 302; urlResolver is deprecated. The frontend must turn that code into a real HTTP redirect, or old URLs only redirect in the browser. Hyvä replaces the theme layer, not Magento’s router, so rewrites behave as described above.

Frequently asked questions

Is it safe to truncate the url_rewrite table?

No. Truncating deletes every friendly URL and every 301 together, and a reindex will not bring them back. Remove specific row types instead, after exporting the redirects that carry links or traffic.

Should I block /catalog/product/view/ in robots.txt?

No. Google says a blocked page “can still be indexed if linked to from other sites,” and blocking hides any canonical on it. Fix the missing rewrite rows so Magento stops producing the URLs.

Does the .html suffix affect rankings?

No. URLs with and without .html rank the same. Changing it on an established store is the risk, because every product and category URL moves and must be redirected.

Why can’t I save “shipping” or “contact” as a URL key?

Both are reserved route names, so Magento rejects them with “The value specified in the URL Key field would generate a URL that already exists.” Adobe’s knowledge base lists 47 reserved words, including checkout, customer and search, and suggests a Custom rewrite with no redirect as a workaround.

Why do ___store and ___from_store URLs appear in my crawl?

The Luma language switcher in 2.4.9 links to stores/store/redirect with those parameters, and crawlers follow the links. Point hreflang at the real store view URLs, never at switcher links.

Are URL rewrites the same on Magento Open Source and Adobe Commerce?

Yes, on Adobe Commerce hosted by Adobe or on your own servers, which share the Open Source core. Adobe Commerce as a Cloud Service is the exception covered above. Open Source is the larger edition: the Magento edition statistics put it at 63.8% of the stores one November 2026 audit could identify.

Where to start

Three checks show most of a store’s rewrite problems:

  1. Read the stored value of Generate “category/product” URL Rewrites, and find out whether the store was installed on 2.4.6 or later or upgraded to it.
  2. Run the row breakdown and the numbered key count above.
  3. Note the count under “Duplicate without user-selected canonical” in the Search Console Pages report.

If those numbers raise more questions than they answer, a free Magento SEO audit covers the rewrite table alongside the rest of the store’s technical setup.

Get a free Magento SEO audit

No obligation. Reply in 1 business day.

More articles