Espen
Espen

Reputation: 147

Magento URL key including hash (#)

I use filter-navigation in magento, so the url for a filtered page displays like this: www.example.com/page#cat=16&gan_data=true

I would like to change the URL key on my categories so that they point to the top level menu including filter settings (like the url abowe), and not to the sub level page.

Problem is, when i save the URL keys like that, the hash tag changes from # to - , so the new url looks like this: www.example.com/page-cat-16-gan-data-true

Is there any way to avoid this?

Upvotes: 2

Views: 2546

Answers (1)

Joe
Joe

Reputation: 1340

The method that formats the URL key is Mage_Catalog_Model_Category::formatUrlKey():

public function formatUrlKey($str)
{
    $str = Mage::helper('core')->removeAccents($str);
    $urlKey = preg_replace('#[^0-9a-z]+#i', '-', $str);
    $urlKey = strtolower($urlKey);
    $urlKey = trim($urlKey, '-');
    return $urlKey;
}

Any non-alphanumeric character will be replaced with a dash. So there's not much you can do without some work.

You have a couple options:

  • Override the class and change the method.
  • Change the backend model through an installer.

The second option would be the most compatible with upgrades, but unfortunately the Catalog URL Rewrites index will reformat the URL key -- through the same method. So you will have to override the Category class to change the formatUrlKey() method.

Upvotes: 2

Related Questions