How can i get a category url rewritten for a specific store in magento?

I have 2 stores: us and uk.

Store codes: en_gb and en_us.

If i load a category in code

$store = Mage::getModel('core/store')->load(3);  // 3 is the uk store
$categoryUrl = Mage::getModel('catalog/category')->load($store->getRootCategoryId())->setStoreId($store->getId());

The url that comes back always has the default website code in the path i.e. and also never the seo friendly url. It is the category/view url



By setting the store in the script the correct country is added to the url:


Why is this needed?

Also it still doesnt give the seo friendly url

2 Answers 2


Magento uses the current store to build the full category url so setting the current store will force it to use the right base URL.

A question posted earlier today might give some more info.


You can also try using the getUrlModel method below:

$store_code = 'something';
$store_id = 2;
$category_id = 234;
$category = Mage::getModel('catalog/category')->setStoreId($store_id)->load($category_id);

$url = $category->getUrlModel()
    ->getDirectUrl($requestPath, array("_store"=>$store_code, "_nosid"=>true));

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.