6

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.

8

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. – musicliftsme Dec 7 '16 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 ? – Vaibhav Ahalpara Jul 20 '17 at 9:45
  • I'm getting "The value of attribute "EXAMPLE_CODE" must be set" error when trying to update website. – Webninja Aug 24 '17 at 11:12
3

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 Oct 30 '18 at 16:59
  • Some products has direct links, some ones - not. The last leads to 404. – Kirby Oct 30 '18 at 17:07
2

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.

0

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:

catalog/product/view/id/1/category/2

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.

e.g.

/mycategory/myproduct.html

This works in Magento 2.1.6

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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