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 – Suman Singh Dec 4 '18 at 10:13
  • thanks for the reply! we've more than 4k products, after changing the url each time should we run this extension? – wakar Ahamad Dec 4 '18 at 11:07
  • you need to run it once only than all will work in further update. – Suman Singh Dec 4 '18 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. – wakar Ahamad Dec 6 '18 at 10:59

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, privacy policy and cookie policy

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