Magento: Get Base Url, Skin Url, Media Url, Js Url, Store Url and Current Url

This post will help you to get base url, skin url, media url, js url, store url and current url in Magento. This is very basic post, that will help to beginners.

Get Url in PHTML Files

Get Base Url:

Mage::getBaseUrl() // Get base url path e.g. http://website.com/
Mage::getBaseUrl('media') // Get MEDIA folder path e.g. http://website.com/media/
Mage::getBaseUrl('js') // Get JS folder path e.g. http:/website.com/js/
Mage::getBaseUrl('skin') // Get SKIN folder path e.g. http://website.com/skin/

Get Current Url:

Mage::helper('core/url')->getCurrentUrl();

Get Home Url:

Mage::helper('core/url')->getHomeUrl();

Create Your Module Url:

Mage::getUrl('module/controller/action');

Get Secure Url:
To get secure url you just need to add one more parameter as below,

Mage::getUrl('', array( '_secure' => true ))
Mage::getUrl( 'module/controller/action' , array( '_secure' => true ))

Get Skin Url:

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);

(a) Get Unsecure Skin Url:

$this->getSkinUrl('images/imagename.jpg');

(b) Get Secure Skin Url:

$this->getSkinUrl( 'images/imagename.gif', array( '_secure' => true ));

Get Media Url:

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);

Get Js Url:

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);

Get Store Url:

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

Get Directory Paths:

Mage::getBaseDir() // output : /var/www/html/magento
Mage::getBaseDir('app') // output : /var/www/html/magento/app
Mage::getBaseDir('media') // output : /var/www/html/magento/media

Same way you can get more directory path,

Mage::getBaseDir('design') // Get design directory path
Mage::getBaseDir('code') // Gives code directory file path
Mage::getBaseDir('lib') // Gives lib directory file path
Mage::getBaseDir('skin') // Gives skin directory file path
Mage::getBaseDir('var') // Gives var directory file path
Mage::getBaseDir('cache') // Gives cache directory file path
Mage::getBaseDir('log') // Gives log directory file path

Get Url in CMS Pages or Static Blocks

Get Base Url:

{{store url=""}}

Get Skin Url:

{{skin url='images/imagename.jpg'}}

Get Media Url:

{{media url='/imagename.jpg'}}

Get Store Url:

{{store url='mypage.html'}}

Hope this helps.

One Comment on “Magento: Get Base Url, Skin Url, Media Url, Js Url, Store Url and Current Url”

Leave a Reply

Your email address will not be published. Required fields are marked *