2

In Mage/Catalog/Model/Product/Url.php, at the end of function getUrl, I added:

/// Added
if($product->getUrlKey()) {
    $routeParams['_direct'] = $product->getUrlKey();
}
///

return $this->getUrlInstance()->setStore($storeId)
            ->getUrl($routePath, $routeParams);

In eav_attribute table, I've set url_key to unique, so editors won't accidentally set same key for multiple products.

And it works, all products have simple url (http://example.com/some-url-key), canonical urls are correct, links in catalog, cart e.t.c. are correct.

I can't find any flaws of this, is it really that simple? Do you know any issues that can appear because of such change?

Thank you.

1 Answer 1

2

Simple solution to include only product key in url is to configure the settings as:

System > Configuration > Catalog > Search Engine Optimization > Use Categories Path for Product URLs = No
2
  • For some reason it didn't work for me. At the end of url_key there was always random 2-4 numbers, not sure why, though.
    – Marvin3
    Commented Apr 7, 2014 at 19:30
  • that means you have duplicate url_keys. Try to find out and fix it. In worst case you can truncate core_url_rewrite table and reindex. (Be sure to check if you have any custom url redirects before truncating the table)
    – MagePsycho
    Commented Apr 8, 2014 at 6:41

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.