How To Regenerate Url rewrites in Magento 2.x / Adobe Commerce 2.x

Magento 2.x / Adobe Commerce 2.x “Regenerate Url rewrites” extension add a CLI feature which allow to regenerate a Url rewrites of products/categories in all stores or specific store.

Need to use below magento2-regenerate_url_rewrites extension

https://github.com/olegkoval/magento2-regenerate_url_rewrites extension

Installation By Composer (“Regenerate Url rewrites” extension)


composer require olegkoval/magento2-regenerate-url-rewrites

How To Enable Extension

enable extension (use Magento 2 command line interface as below):

php bin/magento module:enable OlegKoval_RegenerateUrlRewrites

To make sure that the enabled module is properly registered, run ‘setup:upgrade’:

php bin/magento setup:upgrade

[if needed] re-compile code and re-deploy static view files:

php bin/magento setup:di:compile $> php bin/magento setup:static-content:deploy

HOW TO USE “Regenerate Url rewrites” extension:


Step[1] – To regenerate Url Rewrites of all products in all stores (only products) set entity type to “product”: >

php bin/magento ok:urlrewrites:regenerate --entity-type=product

because product entity type is default – you can skip it:

php bin/magento ok:urlrewrites:regenerate

Step[2] – To regenerate Url Rewrites in the specific store view (e.g.: store view id is “2”) use option –store-id:

php bin/magento ok:urlrewrites:regenerate --store-id=2

Step[3] – To regenerate Url Rewrites of some specific product then use option product-id (e.g.: product ID is “122”):

php bin/magento ok:urlrewrites:regenerate --entity-type=product --product-id=122

or

php bin/magento ok:urlrewrites:regenerate --product-id=122

Step[4] – To regenerate Url Rewrites of specific products range then use option products-range (Example regenerate for all products with ID between “101” and “152”):

php bin/magento ok:urlrewrites:regenerate --entity-type=product --products-range=101-152
  • if in the range you have a gap of ID’s (in range 101-152 products with ID’s 110, 124, 150 not exists) – do not worry, script handle this.

or

php bin/magento ok:urlrewrites:regenerate –products-range=101-152

Step[5] – To save a current Url Rewrites (you want to get a new URL rewites and save current) use option –save-old-urls:

php bin/magento ok:urlrewrites:regenerate --save-old-urls

Step[6] – To prevent regeneration of “url_key” values (use current “url_key” values) use option –no-regen-url-key:

php bin/magento ok:urlrewrites:regenerate --no-regen-url-key

if you do not want to run a full reindex at the end of Url Rewrites generation then use option –no-reindex:

php bin/magento ok:urlrewrites:regenerate --no-reindex

if you do not want to run cache:clean at the end of Url Rewrites generation then use option –no-cache-clean:

php bin/magento ok:urlrewrites:regenerate --no-cache-clean

if you do not want to run cache:flush at the end of Url Rewrites generation then use option –no-cache-flush:

php bin/magento ok:urlrewrites:regenerate --no-cache-flush

if you do not want to display a progress progress bar in the console then use option –no-progress:

php bin/magento ok:urlrewrites:regenerate --no-progress

Regenerate url rewrites of category


Step [1] – To regenerate Url Rewrites of all categories in all stores set entity type to “category”:

php bin/magento ok:urlrewrites:regenerate –entity-type=category

Step [2] – To regenerate Url Rewrites of some specific category then use option category-id (e.g.: category ID is “15”):

php bin/magento ok:urlrewrites:regenerate –entity-type=category –category-id=15

Step [3] – To regenerate Url Rewrites of specific categories range then use option categories-range (e.g.: regenerate for all categories with ID between “4” and “12”):

php bin/magento ok:urlrewrites:regenerate --entity-type=category --categories-range=4-12

if in the range you have a gap of ID’s (in range 4-12 category with ID “6” not exists) – do not worry, script handle this.

If you use options –category-id or –categories-range then you can skip option –entity-type=category – extension will understand that you want to use a category entity.