Based on this answer, you can fetch baseurl from backend with his code:


This won't work properly, if settings 'Add Store Code to Urls' is set to 'Yes' (details about that). In this case, it will add 'admin' into url.

I noticed that also


won't display proper url, it will add admin into url on fresh Magento installation.

Is that Magento bug? Is there any other proper way to get frontend base url from backend?

1 Answer 1


Try it like this:

$storeId = 1; //the store you need the base url:
$homeUrl = Mage::getUrl('', array('_store' => $storeId));

For a product url do this:

$url = Mage::getModel('catalog/product')->setStoreId($storeId)->load(1)->getProductUrl();

$storeId is the same as above.

  • I just realized that I should not leave $storeId null because in such case Magento will take current store which is admin when inside backend.
    – JohnyFree
    Dec 11, 2014 at 15:47

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.