Magento 2 troubleshooting › Catalogue
How do I fix “URL key for specified store already exists”?
Short answer: The path the product wants is already taken in that store view, by another product with the same url_key, or by a category, CMS page or custom rewrite. Find who owns it, then change one of them.
Check it step by step
These queries only read data. Run them on a copy of your database if you can, or ask your developer to. If your tables have a prefix (set in app/etc/env.php), add it to each table name.
1. Who owns the path?
Works on Magento Open Source and Adobe Commerce:
SET @path = 'your-product.html'; -- the URL key plus your suffix
SELECT store_id, entity_type, entity_id, target_path, redirect_type
FROM url_rewrite
WHERE request_path = @path;
2. Products sharing a URL key
Magento Open Source
SELECT u.value AS url_key, u.store_id, COUNT(*) AS products, GROUP_CONCAT(e.sku) AS skus
FROM catalog_product_entity_varchar u
JOIN eav_entity_type t ON t.entity_type_code = 'catalog_product'
JOIN eav_attribute a_url_key ON a_url_key.entity_type_id = t.entity_type_id AND a_url_key.attribute_code = 'url_key'
JOIN catalog_product_entity e ON e.entity_id = u.entity_id
WHERE u.attribute_id = a_url_key.attribute_id
GROUP BY u.value, u.store_id
HAVING products > 1
ORDER BY products DESC;
Adobe Commerce
Product, category, rule and CMS values are stored per version and joined on row_id (why):
SELECT u.value AS url_key, u.store_id, COUNT(*) AS products, GROUP_CONCAT(e.sku) AS skus
FROM catalog_product_entity_varchar u
JOIN eav_entity_type t ON t.entity_type_code = 'catalog_product'
JOIN eav_attribute a_url_key ON a_url_key.entity_type_id = t.entity_type_id AND a_url_key.attribute_code = 'url_key'
JOIN catalog_product_entity e ON e.row_id = u.row_id
AND e.created_in <= UNIX_TIMESTAMP() AND e.updated_in > UNIX_TIMESTAMP()
WHERE u.attribute_id = a_url_key.attribute_id
GROUP BY u.value, u.store_id
HAVING products > 1
ORDER BY products DESC;
Two products with the same key in the same scope can't both have a URL. Imports that build keys from names hit this often.
How to fix it
- Give one of the products a different URL Key (Search Engine Optimization section) and save it.
- If the path belongs to an old custom redirect you no longer need, delete it in Marketing › SEO & Search › URL Rewrites.