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?


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);
  • You might need to cast $url as a string, but great answer. – Goose Feb 27 '18 at 16:36
  • With system config fallbacks, Mage::getStoreConfig('web/unsecure/base_url', $website->getDefaultStore()->getId()); – Steve Robbins Apr 3 '18 at 0:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.