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

Retrieving URLs in Magento

1. Get Base URL


<?php

$base_url = Mage::getBaseUrl();

?>

2. Get Current URL


<?php

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

?>

3. Get Home URL


<?php

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

?>

4. Get Store URL


<?php

$store_url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

?>

5. Get Media URL


<?php

$media_url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);

?>

6.  Get Skin URL


<?php

$skin_url =Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);

?>

7.  Get Js URL


<?php

$js_url =Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);

?>

 

In PHTML files the following code may be used

1. Not secure Skin URL

<?php

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

?>

2. Secure Skin URL

<?php

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

?>

 

In CMS Pages/Static blocks the following code may be used

1. To get SKIN URL


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

2. To get Media URL


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

3. To get Store URL


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

4. To get Base URL


{{base url='yourstore/pagename.html'}}

 

Retrieve urls in base64 encoding

1. Current URL


<?php

$current_url_base64 = Mage::helper('core/url')->getCurrentBase64Url();

?>

2. Encode a url to base 64


<?php

$url_base64 = Mage::helper('core/url')->getEncodedUrl($url);

?>

If $url is not passed to function getEncodedUrl() then it return the current URL base 64 encoded

Leave a Comment

Back to top