How to get base url in Magento?

The "Base URL" field should either match the site's domain or, if you have purchased a Private SSL certificate for the site, here you should type the https form of the URL of your Magento store.
In order to configure Magento to work with a new domain or change its current directory, you can follow the solutions:

First look at getBaseUrl() at Mage.php

<?php 
public static function getBaseUrl($type = Mage_Core_Model_Store::URL_TYPE_LINK, $secure = null)
{
return self::app()->getStore()->getBaseUrl($type, $secure);
}
?>

In a simple word we can say:

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) indicated Your Magento Site Url from this URL Magento is running it System.

And other word ,we can say that Mage::getBaseUrl() give the URL which is linking your Magento internal page URLs That MVC page

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB):

Admin > System > Configuration > WebSite > Secure/Unsecure > Base url

Mage::getBaseUrl():

Admin > System > Configuration > WebSite > Secure/Unsecure > Base Link url

Change base URL from Magento Admin

If you are able to log into Magento's backend, you can easily modify the base URLs of the site via:

  1. Log in to your Magento Admin Panel
  2. On the upper right, click System > Configuration.
  3. From the menu on the left, under the General list, click Web.
  4. Open the Unsecure and Secure dropdowns, locate the base URL line, and replace this with the new URL.
  5. Clear the Magento cache and your browser's cache. The site should now load properly.

Change base URL via Phpmyadmin

If you do not have access to the backend anymore, you need to modify the URL within the database.
Simply open up the database using phpMyAdmin, then navigate to the core_config_data table inside.
Click the Browse tab and edit the first two fields:

  • web/unsecure/base_url
  • web/secure/base_url

Join our Newsletter

Never miss the latest offers, voucher codes and useful articles delivered weekly in your inbox.