How to Get Base URL of Default Website in Magento 1.9

base-urldefaultmagento-1.9urlwebsites

I need to use the function file_get_contents() on default website's base URL.
Currently there are many websites in magento system.
How to get the id of default website and base URL?

Best Answer

You can get the default website id like this:

$websites = Mage::getModel('core/website')->getCollection()->addFieldToFilter('is_default', 1);

$website = $websites->getFirstItem();
$websiteId = $website->getId();
$websiteCode = $website->getCode();

and you can get the base url like this:

$url = Mage::getConfig()->getNode('web/unsecure/base_url', 'website', $websiteCode);
Related Topic