olegkoval / magento2-regenerate-url-rewrites
olegkoval/magento2-regenerate-url-rewrites
Add into Magento 2 a CLI feature which allow to regenerate a Url Rewrites of products and categories
“Regenerate Url Rewrites” extension
Magento 2 "Regenerate Url Rewrites" extension add a CLI feature which allow regenerating a Url rewrites of products/categories in all stores or specific store.
Extension homepage: https://github.com/olegkoval/magento2-regenerate_url_rewrites
CONTACTS
- Email: [email protected]
- LinkedIn: https://www.linkedin.com/in/oleg-koval-85bb2314/
DONATIONS / SUPPORT ME ON
INSTALLATION
COMPOSER INSTALLATION
- run composer command:
$> composer require olegkoval/magento2-regenerate-url-rewrites
MANUAL INSTALLATION
-
extract files from an archive
-
deploy files into Magento2 folder
app/code/OlegKoval/RegenerateUrlRewrites
ENABLE EXTENSION
- enable extension (use Magento 2 command line interface *):
$> 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 IT:
- 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
- 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
- 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
- to regenerate Url Rewrites of specific products range then use option
products-range(e.g.: 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, a script handles this.
or
$> php bin/magento ok:urlrewrites:regenerate --products-range=101-152
- 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
- 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 bar in the console then use option
--no-progress:
$> php bin/magento ok:urlrewrites:regenerate --no-progress
REGENERATE URL REWRITES OF CATEGORY
- to regenerate Url Rewrites of all categories in all stores, set an entity type to "category":
$> php bin/magento ok:urlrewrites:regenerate --entity-type=category
- 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
- 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, a script handles 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.
YOU CAN COMBINE OPTIONS
$> php bin/magento ok:urlrewrites:regenerate --store-id=2 --save-old-urls --no-regen-url-key --no-reindex
YOU CANNOT COMBINE THESE OPTIONS
--entity-type=productand--category-id/--categories-range--entity-type=categoryand--product-id/--products-range--category-idand/or--categories-rangeand/or--product-idand/or--products-range
DEPRECATED OPTIONS
--check-use-category-in-product-url— extension uses a built-in Magento Url Rewrites generator which check this option in any way.
EXAMPLES OF USAGE
- Regenerate Url Rewrites for product with ID "38" in store with ID "3":
$> php bin/magento ok:urlrewrites:regenerate --entity-type=product --store-id=3 --product-id=38
or
$> php bin/magento ok:urlrewrites:regenerate --store-id=3 --product-id=38
- Regenerate Url Rewrites for products with ID's 5,6,7,8,9,10,11,12 in store with ID "2" and do not run full reindex at the end of process:
$> php bin/magento ok:urlrewrites:regenerate --entity-type=product --store-id=2 --products-range=5-12 --no-reindex
- Regenerate Url Rewrites for category with ID "22" in all stores and save current Url Rewrites:
$> php bin/magento ok:urlrewrites:regenerate --entity-type=category --category-id=22 --save-old-urls
- Regenerate Url Rewrites for categories with ID's 21,22,23,24,25 in store with ID "2":
$> php bin/magento ok:urlrewrites:regenerate --entity-type=category --categories-range=21-25 --store-id=2
Enjoy!
Best regards,
Oleg Koval
"Regenerate Url Rewrites" Change Log
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
[1.7.2] - 2026-03-31
Changed
- fixed deprecated functionality: ctype_digit()
- improved SQL safety in URL rewrite regeneration queries
- fixed SQL escaping in URL rewrite cleanup logic
- fixed _clearRequestPath() to correctly handle multiple consecutive slashes
- removed dead code from category URL rewrite model
- display validation errors before command failure
- display a completed progress bar for empty product/category collections
- normalized line endings to LF
[1.7.1] - 2025-05-30
Changed
- adapted for compatibility with PHP 8.4 (deprecated implicitly nullable types)
[1.7.0] - 2025-04-15
Changed
- adapted for compatibility with Magento 2.4.7-p4
- adapted the composer.json file to be compatible with Composer 2
[1.6.2] - 2023-10-10
Changed
- fixed Symfony Command constant issue
- exclude non visible products from url regeneration
[1.6.1] - 2023-08-24
Changed
- fixed compatibility with Symfony Console 5 and Magento 2.4.6
- updated contact email to Gmail email (my own domain olegkoval.com was stolen)
[1.6.0] - 2021-01-27
Changed
- adapted to Magento 2.3.5
- fixed incorrect generation when URL suffix is slash
[1.5.6] - 2020-04-13
Changed
- updated logic of "cleaning" of Url Rewrites and duplications check
[1.5.5] - 2020-04-02
Changed
- updated logic of Url Rewrite regeneration via category entity
- fixed compilation issue in helper
[1.5.4] - 2020-03-21
Changed
- fixed issue of non-empty/non-false "request_path" of product entity.
- modified logic of Url Rewrite db table updates
[1.5.3] - 2020-03-20
Changed
- updated Url Rewrite preparing function
- updated logic of Url Rewrite regeneration via category entity
- updated save logic
[1.5.2] - 2020-03-18
Changed
- updated logic of Url Rewrite regeneration via category entity
- CLI options logic optimized (for category entity)
[1.5.1] - 2020-03-08
Changed
- fixed issue of url_key and url rewrites regeneration based on product name value
[1.5.0] - 2020-02-26
Changed
- revised and restructured code
- modified functional logic of extension
- removed option "--check-use-category-in-product-url"
[1.4.3] - 2019-05-12
Added
- new option "no-regen-url-key"
Changed
- fixed a "typo" issue
[1.4.2] - 2019-04-04
Added
- new option "--check-use-category-in-product-url"
- info into log about conflicted URL Rewrites
Changed
- fixed logical issues in url_key regeneration
- a fix for category/products rewrites for multistore
- fixed issue of division by zero in progress bar
- update the url_key regeneration behavior to use UrlPathGenerators
- modified logic of displaying console messages (notifications, errors, exceptions...)
[1.4.1] - 2019-02-20
Changed
- fixed the issue of removing previously added URL rewrites of product when the same URL key exists;
- modified progress bar
[1.4.0] - 2019-02-11
Added
- new option "--entity-type"
- new option "--products-range"
- new option "--product-id"
- new option "--category-range"
- new option "--category-id"
Changed
- revised and restructured code
- modified logic of url rewrites regeneration
- removed "--clean-url-key"
[1.3.1] - 2018-11-14
Changed
- fixed issue of empty product URL keys
- fixed double slashes issue
- update category attributes via resource saveAttribute()
- use proxy for CategoryUrlPathGenerator
[1.3.0] - 2018-10-29
Added
- new option "--no-cache-clean"
- new option "--no-cache-flush"
- new option "--no-progress"
- new option "--no-clean-url-key"
Changed
- optimized code
- modified logic of url rewrites regeneration
- fixed issue of store filter in a category collection
[1.2.3] - 2018-10-03
Added
- display additional debug information for "URL key for specified store already exists" error
Changed
- modified logic of url rewrites regeneration
[1.2.2] - 2018-10-02
Changed
- fixed setStoreId() on null error
[1.2.1] - 2018-09-25
Changed
- fixed compilation issues
[1.2.0] - 2018-09-25
Changed
- added proxies to CLI commands
- modified logic of url rewrites regeneration
- updated a composer file
- fixed issue of a compatibility with new Magento Commerce versions
[1.1.1] - 2018-09-10
Changed
- fix composer file format issue
[1.1.0] - 2018-09-09
Added
- added feature to add a Pro features through a "Layer" class
Changed
- fix issue when optional arguments require value
- updated a code structure
[1.0.6] - 2018-07-26
Added
- new option to run URL rewrite generation without running full reindex
Changed
- update help notice to show INPUT_KEY_SAVE_REWRITES_HISTORY and INPUT_KEY_NO_REINDEX
[1.0.5] - 2018-05-13
Added
- new option to save current URL rewrites
Changed
- improve the store ID arguments workflow
[1.0.4] - 2017-11-13
Added
- additional checks of storeId argument
[1.0.3] - 2017-10-25
Added
- check if area code is set
[1.0.2] - 2017-10-20
Fixed
- fix "Area code not set" issue
[1.0.1] - 2017-10-10
Fixed
- fix store id issue in collection filter
[1.0.0] - 2017-09-29
Release of Magento 2 "Regenerate Url Rewrites" extension
| Version | Stability | QA Status | Released |
|---|---|---|---|
| 1.7.2 | stable | Fail | 2026-04-07 11:58:33 |
| 1.7.1 | stable | Not tested | 2025-05-30 08:50:45 |
| 1.7.0 | stable | Not tested | 2025-04-17 08:57:27 |
| 1.6.2 | stable | Not tested | 2023-10-10 16:03:11 |
| 1.6.1 | stable | Not tested | 2023-08-24 08:11:18 |
| 1.6.0 | stable | Not tested | 2021-01-27 19:08:16 |
| 1.5.6 | stable | Not tested | 2020-04-14 12:37:22 |
| 1.5.5 | stable | Not tested | 2020-04-02 09:38:49 |
| 1.5.4 | stable | Not tested | 2020-03-21 13:20:23 |
| 1.5.3 | stable | Not tested | 2020-03-21 00:52:01 |
| 1.5.2 | stable | Not tested | 2020-03-18 13:09:43 |
| 1.5.1 | stable | Not tested | 2020-03-08 13:19:47 |
| 1.5.0 | stable | Not tested | 2020-02-26 00:39:38 |
| 1.4.3 | stable | Not tested | 2019-05-12 16:26:18 |
| 1.4.2 | stable | Not tested | 2019-04-04 19:25:24 |
| 1.4.1 | stable | Not tested | 2019-02-22 18:50:45 |
| 1.4.0 | stable | Not tested | 2019-02-10 23:31:00 |
| 1.3.1 | stable | Not tested | 2018-11-14 01:09:36 |
| 1.3.0 | stable | Not tested | 2018-10-29 21:35:32 |
| 1.2.3 | stable | Not tested | 2018-10-03 17:50:49 |
| 1.2.2 | stable | Not tested | 2018-10-02 10:16:34 |
| 1.2.1 | stable | Not tested | 2018-09-25 08:06:32 |
| 1.2.0 | stable | Not tested | 2018-09-24 23:20:50 |
| 1.1.1 | stable | Not tested | 2018-09-10 05:45:05 |
| 1.0.6 | stable | Not tested | 2018-07-26 20:52:28 |
| 1.0.5 | stable | Not tested | 2018-05-12 23:15:48 |
| 1.0.4 | stable | Not tested | 2017-11-13 13:46:25 |
| 1.0.3 | stable | Not tested | 2017-10-25 11:32:32 |
| 1.0.2 | stable | Not tested | 2017-10-20 00:25:54 |
| 1.0.1 | stable | Not tested | 2017-10-10 08:12:20 |
| 1.0.0 | stable | Not tested | 2017-09-29 10:23:11 |
No dependencies declared
This package's composer.json doesn't declare any required, suggested, replaced, or conflicting packages.
| Tool | Status | Findings | Summary |
|---|---|---|---|
| PHPCS | Fail | 12 | 12 errors (gating threshold: error-severity=10, ruleset: Magento2) |
| PHPStan | Fail | 1 | 1 errors (level 4, ruleset: phpstan + bitexpert/phpstan-magento) |
| Cpd | Pass | 0 | |
| Security | Pass | 0 |
Turn an existing module into recurring revenue.
If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.