Mauserrifle.nl Tech and Life

    Home     Archive     Projects     Contact

Magento 2 Wrong Product Canonical Url

Unfortunately Magento 2 can add the wrong product canonical tag containing a 301 redirect URL. In the following file and method it can be fixed:

vendor/magento/module-catalog/Model/Product/Url.php::getUrl()

Add redirect_type code above the urlFinder code:

$filterData['redirect_type'] = 0 ;
$rewrite = $this->urlFinder->findOneByData($filterData);

It might be fixed in newer Magento 2 versions. This was discovered in version 2.3.6.

If you liked this post, you can share it with your followers!