I was changing all my categories URLS to match my old website when i notices magento kept changing them when I click saved.

For example i would write "nike_air_force_one" and once i clicked saved magento would change it to "nike-air-force-one"

SO my questions is how can I stop it form changing my URLS as I need them to match my old site for Google ratings?

1 Answer 1


The url key passes through this method before saving it: Mage_Catalog_Model_Category::formatUrlKey that looks like this:

public function formatUrlKey($str)
    $str = Mage::helper('catalog/product_url')->format($str);
    $urlKey = preg_replace('#[^0-9a-z]+#i', '-', $str);
    $urlKey = strtolower($urlKey);
    $urlKey = trim($urlKey, '-');
    return $urlKey;

The first line just translates some characters. For example ê becomes e.
The second line replaces everything that is not numerical or a letter with -.
So you need to add underscore in that regular expression.

$urlKey = preg_replace('#[^0-9a-z_]+#i', '-', $str);

But please don't modify the core core. Just rewrite the category model.


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.