23

I have recently created 2 additional store view on magento 2 store. Now the url of category and Products are not for those stores is not proper

Eg: http://example.com/catalog/category/view/s/pouches/id/20/ which is suppose to be http://example.com/accessories/pouches.html

Now when I save each product and category one by one it regenerate url rewrite for that product or category.

But there are lots of products and category.

So is there any way to regenerate URL rewrite

as in Magento 1.x it can be done via reindexing.

  • In Magento 2 url rewrite module does not use Indexer to create rewrites. Rewrite is generated in process of save/import of product/categories/cms pages. So you might need to go the programmatically way of loading and saving the categories – mp196 Jan 11 '17 at 7:09
  • can you suggest me some reference to create script to do so. – Arun Karnawat Jan 11 '17 at 7:21
  • You need to Re indexing again. – Vaibhav Jain Jan 11 '17 at 8:02
  • I have already try indexing, There is not URL Rewrite Index in Magento 2. So it do not worked. I have reindex now again, its not working – Arun Karnawat Jan 11 '17 at 8:42
  • 1
    For products what you try is select all of them from grid, And select update attributes and in websites tab select the website (though products are already assigned to the same website) This shall resave the product and might regenerate url rewrites. – mp196 Jan 11 '17 at 8:49

10 Answers 10

16

This module is been deprecated you can use this module instead

Download Using Composer;

composer require elgentos/regenerate-catalog-urls

php bin/magento setup:upgrade

Regenerate url for all products and the global store

php bin/magento regenerate:product

Regenerate url for products with id (1, 2, 3, 4) for store 1

php bin/magento regenerate:product:url -s1 1 2 3 4

  • that module is buggy, but still can help in some cases. – Gediminas Jun 26 '17 at 13:36
  • Yes, and it will be helpful for us to use those methods to trigger product url rewrites. – Lead Developer Jun 27 '17 at 8:15
  • 1
    Currently, doesn't work in 2.1.9 ... – Spyrule Oct 17 '17 at 20:55
  • @Spyrule I'm on 2.1.9 and experienced issues. However after logging my issue, someone pointed me to this pull request that hasnt been approved yet works a charm for me: github.com/Iazel/magento2-regenurl/pull/21/commits/… – David Wilkinson Oct 18 '17 at 14:45
  • @Gerdiminas what bugs do you know about? – harri Nov 9 '17 at 16:38
19

You can use Regenerate a Url rewrites extension (it allow to 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
  • 1
    This extension working perfectly for me. Thanks for your extension. – mapaladiya Dec 20 '17 at 2:09
  • it works very good! thx! – LucScu Feb 2 '18 at 16:27
  • Does this delete the old rewrites? – Matthew McLennan Feb 14 '18 at 18:46
  • 1
    Is it still working? It doesn't for me. – Kirby Nov 7 '18 at 14:43
  • 1
    @OlegKoval I have installed version 1.3.1 but still it doesn't work for me. So what is the issue behind this? – Chintan Kaneriya Dec 18 '18 at 11:28
3

In update to @mahendra Jella's answer, Try this branch of the same extension: https://github.com/PascalBrouwers/magento2-regenurl/tree/feature/generate_category

This one can regenerate URLs for categories too.

The command goes as follows:

php bin/magento iazel:regenurl
# Regenrate Category URL keys >
php bin/magento iazel:regenerate_urls
  • This extension worked beautifully for me in 2.1.9. Helped identify duplicate url products by ID as well (albeit, a minor update to list the sku would be useful). – Spyrule Oct 17 '17 at 22:34
  • This extension not work for me magento 2.2.9 – jruzafa Aug 30 at 7:58
3

There is actually an easy way to fix this without a lot of trouble. For the TL:DR people, the bold parts are relevant.

One thing to check first; if you have multiple store views, go into the product and switch the view to particular view. Scroll down and make sure the URL-Key is set to "Use Default Value". If that isn't checked, it will never generate. I think this can happen when you import M1 products. I had 200+ products that needed touched up.

This fix also helps if you do the trick where you switch your store to a different root and back, which cleans out everything. Including your custom ones. And it can finish with nothing but the category URL's. Not sure why the URL generation for products fails completely but I think it's because Magento is trying to make too many links in one operation which fails.

So give this a shot. Open the URL rewrite window and note the number of entries. This let's you know if it works.

Go into a first level category (it doesn't work on default because is doesn't have a URL key). Scroll down to Search Engine Optimization / URL-Key. Add an X to the end of the key. Uncheck the "Create Permanent Redirect for old URL", it only adds more work to the operation. Save your category.

Repeat the operation and remove the X, again uncheck the "Create Permanent Redirect for old URL", because you don't need those old URL's clogging up the table. Save again.

Refresh the URL rewrite page and you should see a new number, and shiny new URL's.

Repeat as needed.

FYI really big categories may time out. So in those cases, do the smaller sub-categories by themselves. On my server that threshold is about 400 entries.

Magento is smart enough to make the links for the category above your sub-categories. It is also smart enough that when it see's a product in another category, it builds the links for there too.

Took me a while to figure out why I was seeing fewer and fewer links added as I went down the category list. It was because a majority of products were already in the table and just the stragglers that hadn't appears before remained.

0

So, I had this issue for products and fixed this by using the mass update feature to remove all products from the store and then re-adding them. I didn't have very many categories, so I just went in and re-saved them.

Overall, I think avoiding the ole' truncate and regenerate tactic we did in Magento 1 is probably best. If your product rewrites look wrong, just do what I posted above and that should correct them.

0

As per I know Magento 2 does not provide this feature, but I am using this extension

http://shreejiinfosys.co.in/url-rewrite-generator-magento-2.html

from this I can able to regenerate category and all product url.

Note: I am not promoting the extension hence I am using this extension and its quite useful for me.

0

I too had that issue, I m using magento 1.9.2.4, magento does no provide any method to regenerate custom urls. So what i did is little off the table, and it solved the issue, i never tried magento url rewrite extension so can not say how they work.

Note- Maybe you should not consider this if you have too many custom url rewrite.

Magento regenerates its default redirects so if a custom rewrite causing an issue, you can truncate core_url_rewrite table from your magento database.

enter image description here

Be sure to make backup of the database before doing so.

  • That is the whole point unlike magento 1, magento 2 do not have index to regenerate url. Question Is about Magento 2.1 – Arun Karnawat Sep 8 '17 at 8:15
0

Unfortunately none of these extensions/modules have worked for me. I have about 4000 products and moving from Magento 1.9.2.4 to 2.2.2. I used the Data Migration tool and it worked like a charm, other than this issue.

Some of my products have url keys and some do not. I only have one store which is the frustrating part. It looks like Magento considers the admin a store.

The only thing that has worked for me was importing the products with 'replace' option. And for SEO purposes I don't want to change the url's of my products, not even if it's just adding a number after.

I'm going to try deleting the url rewrites for products only.

0

I ran into a similar problem. In Magento 1, it was possible to truncate the url rewrite table and reindex. Magento 2 does not have a url rewrite indexer, so this is not an option.

Many suggest the Iazel extension. I went with the extension by Olgeg Koval, and it worked beautifully. Running Magento 2.2, it deleted all existing url rewrites and regenerated them for all store views. Zero problems.

0

All you need to do in order to regenerate rewrites is to initiate a rewrite. Go to a category or product and change its url in the SEO section of the product/category by adding a "a-" to the front of it. For example:

Url = "product-name" New Url = "a-product-name"

This will trigger the rewrite and redo all other rewrites.

  • This only works if you have a handful of rewrites. With more than 100 products stuck on the old URL this is no feasible solution. – Jacques Oct 2 at 14:22

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.