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 (http://www.magentocommerce.com/wiki/5_-_modules_and_development/reference/geturl_function_parameters) 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.