I have migrated from Magento 1 to Magento 2 and when updating/changing the URL key of a migrated products "Test" from "test" to "test2" still getting old URL of this product on the frontend "mydomainname/test.html" while it should be "mydomainname/test2.html".

but When I deleted old URL key and added new URL key from "URL Rewrite" module then I'm able to access product directly by new URL(mydomainname/test2.html).

Suppose this product "Test" is assigned in the category "XYZ". when I visited on XYZ category page to visit on "Test" product then instead of getting "Domainname/XYZ/test2.html" URL getting a strange URL for the "Test" product only. while other migrated products URL in this category is very user-friendly ("Domainname/XYZ/urlkey.html").

Note:- I've already gone through the R&D and didn't get any useful solution. Already performed reindexing, cache clean etc.

  • use this extension: github.com/olegkoval/magento2-regenerate_url_rewrites Commented Dec 4, 2018 at 10:13
  • thanks for the reply! we've more than 4k products, after changing the url each time should we run this extension? Commented Dec 4, 2018 at 11:07
  • you need to run it once only than all will work in further update. Commented Dec 4, 2018 at 11:30
  • I tried the extension but it took too much time to create url_key. after running the Ext 4-5 HR i left the system for an entire night with running the Ext but in the morning i don't know how my console was closed and frontend categories stopped working getting 404 page. Finally i resolved the issue by updating url-key via import. Commented Dec 6, 2018 at 10:59

1 Answer 1


As I R&D and found that this is a migration issue:-

Solution 1:- I've fixed the migration issue, to fix the issue you need to override the method "getUrlPath()" of the class "\Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator":-

Here is the override class code :-


namespace Namespace\MigrationUrlKeyIssue\Model\Magento\CatalogUrlRewrite;

class ProductUrlPathGenerator extends \Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator
     public function getUrlPath($product, $category = null)
        // $path = $product->getData('url_path');
        $path=null ;
        if ($path === null) {
            $path = $product->getUrlKey()
                ? $this->prepareProductUrlKey($product)
                : $this->prepareProductDefaultUrlKey($product);
        return $category === null
            ? $path
            : $this->categoryUrlPathGenerator->getUrlPath($category) . '/' . $path;


Solution 2:- I tried to update the url_key by-product import and its work for me but this is not a perfect solution as you can't always export and import products so, always prefer solution 1.

Hope it'll help you guys!!!

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.