How to solve Specified URL key already exists error during Magento 2 import

- E-Commerce, Magento 2

When creating or importing categories and products some may encounter Magento 2 error message ‘URL key for specified store already exists’. It may be the URL rewrites, database issue or other things not considered.

Anyways, if there is an error there will also be a solution. In this article we will talk about how to solve Magento 2 ‘URL key for specified store already exists’ error when importing products and categories to your store.

The error can be encountered when creating and managing products or categories. However, in this very article we will talk about how to solve the error when importing products or categories to your Magento 2 store.

Before we start, what may cause the error message ‘URL key for specified store already exists’? At the Magento 2 Stackexchange and GitHub users specified the following cases:

  1. Incorrect URL rewrites in table url_rewrite.
  2. Wrong attribute id in table catalog_category_entity_varchar.
  3. There is actually a category or a product with the same URL.

Anyways, you can pretty much skip all these errors when importing categories and products if you are using Improved Import and Export extension for Magento 2.

How to get rid of duplicate URLs

Improved Import and Export extension introduces jobs allows for import and export process automation. In addition, every jobs comes with Generate Unique Url if Duplicate setting which we are looking for.

How this setting works? Well, if Generate Unique Url if Duplicate is enabled then, when you are importing products or categories with the same URL the extension will make sure to either create new URL using product attributes, or increment URL if you are importing categories.

For products

When you are importing products with the same URL the extension recomposes the URL of the second product on the following pattern:

Product name + product SKU + increment value (1+)

For example:

If you are importing Magento 2 product with:

Name = New Product

SKU = test

Then, if this product’s url is a duplicate, the extension will generate a new URL which will look like:

New-product-test-1

For categories

When you are importing categories with the same URL the extension increments the duplicate URLs on the following pattern:

url_key + 1

If such URL already exists the extension will add another “+1”.

For example:

If you are importing Magento 2 category with url=test_category and it is a duplicate the extension will increment this URL to look like:

test_category1

That’s it, with Improved Import and Export extension you don’t have to worry about URL duplicate error.

Buy Improved Import Magento 2 Extension