Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email

Magento Forum

Mage::getUrl doesn’t search rewrites
Paul Bunkham
Jr. Member
Total Posts:  3
Joined:  2010-07-20


I’m sure I’m just missing something, but I’ve got rewrites turned on for categories and I’m not getting the expected result when I call Mage::getUrl(’catalog/category/view’,array(’id’=>4,’_use_rewrite’=>true))

In the rewrite rules I have a rule that has the request path as ‘jewellery/’ and the target path as ‘catalog/category/view/id/4’. Looking at the documentation for getUrl ( it says that setting _use_rewrite to true should cause the module/controller/action/parameters to be looked up in the database, but the above call just returns the url http://magento.local/catalog/category/view/id/4 instead of http://magento.local/jewellery/ as expected.

The rewrite rule is working as going to http://magento.local/jewellery/ displays the category as expected, and I think the problem might be that this database lookup never actually happens. Looking at the code I’ve tracked down the rewrite check to the getRoutePath method in Mage_Core_Model_Url. This checks if there’s a rewrite equivalent for the current request url and if so, uses that path, but it doesn’t check it for the path passed in.

I know you could get the category url in other ways, but this would be a problem for any rewrite. I might have a custom module that sets up its own rewrite rules and calling getUrl with the correct parameters should return the SEO friendly equivalent, but I don’t see how that would be the case.

Has anyone got any experience with this? I’ve searched around but can’t see anyone else having this problem, although that could be because I’m the only one doing it wrong!

Any help would be really appreciated.



Magento Community Magento Community
Magento Community
Magento Community
Jr. Member
Total Posts:  7
Joined:  2011-11-01

Ive just had I think exactly the same issue. As far as I can see it looks as though the rewrites only work one-way? Ie, if you create a rewrite ruule and enter the new url into your browser’s address bar it works and goes to the right place. But using Mage::getUrl(’mymodule’, array(’_use_rewrite’ => true)); to generate the rewritten url doesnt seem to lookup the rewrites.

To get around this I created my own function in a helper to get the rewritten url for my module… its a bit rubbish but:

$rewrite Mage::getModel('core/url_rewrite');
            if (
Mage::app()->getStore()->getId()) {
// Look for a rewrite rule with this id

// If found return our URL rewrite
if ($rewrite->getId()) {
return Mage::getUrl($rewrite->getRequestPath());
// Else return standard URL
return $idPath;

Is this (as I would hope) totally unnecessary? Is this a bug?


Magento Community Magento Community
Magento Community
Magento Community
Jr. Member
Total Posts:  26
Joined:  2011-09-19

I placed a bug report:

Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top