Is there a way to force Magento 2 to redo all of the product/category urls? The majority of the site is fine with urls such as category-name/product.html but a few categories refuse to conform to the same rules.

Before I could get rid of the table and reindex but this option no longer exists.

5 Answers 5


I currently use this to update the url keys of certain products:

  1. Update 'url_key' attribute through Magento Import
  2. Admin --> Products Catalog --> Select the products you imported the new url_key for --> Actions: Update Attributes --> Websites: Add to website You can just tick the website it is already assigned to. This way the product gets 'updated' and it writes the new imported url_key to the url_writes table
  • This method still works on 2.1.2.
    – laketuna
    Commented Dec 7, 2016 at 6:16
  • This solution work for me. can you please explain why ? I mean i try to save to save product and save category but it's not working but when i update attribute it works how ? Commented Jul 20, 2017 at 9:45
  • I'm getting "The value of attribute "EXAMPLE_CODE" must be set" error when trying to update website.
    – Webninja
    Commented Aug 24, 2017 at 11:12

You can use Regenerate a Url rewrites extension (it allow to generate/regenerate a Url rewrites of products and categories) .

To re-generate all Url rewrites of the categories/products in all stores (it support a multistores) run:

$> bin/magento ok:urlrewrites:regenerate

To regenerate Url rewrites in the specific store view (e.g.: store view id is "2"):

$> bin/magento ok:urlrewrites:regenerate 2
  • Just double checked, it doesn't work unfortunately. :-/
    – Kirby
    Commented Oct 30, 2018 at 16:59
  • Some products has direct links, some ones - not. The last leads to 404.
    – Kirby
    Commented Oct 30, 2018 at 17:07

It seems that Magento 2 isn't regenerating rewrites on reindexing. Url rewrites are generated when product/category/page is saved/imported. So probaly your only solution is to write a script which will go through all products and resave them.

You can read more about this "issue" on github.


If (like me) you accidentally deleted some of the Magento 2 URL rewrites for a product and so you see horrible URLs like the following:


You can simply edit the category for the products where you are missing URL rewrites and save it.

Magento 2 then re-creates URL Rewrites for the products in that category.



This works in Magento 2.1.6

  • 1
    For some reason this does not work in my case.
    – Webninja
    Commented Aug 24, 2017 at 11:10
  • 3
    @Webninja same here. I do not know why saving the category doesn't generate the URL keys again. Oleg Koval solution works fine tho. Commented Mar 2, 2018 at 13:51

If you have access to the magento cli you can type this cmd

For a target store : $ php bin/magento ok:urlrewrites:regenerate --store-id=1

For a all stores : php bin/magento ok:urlrewrites:regenerate

  • You forgot to mention that this needs the extension from oleg koval...
    – Black
    Commented Dec 30, 2021 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.