Monday, May 9

How to get Current URL in Magento

Here is the code to get current page url in magento

$currentUrl = $this->helper('core/url')->getCurrentUrl();

// Gives the base url of your magento installation
$baseUrl = Mage::getBaseUrl();

// Gives the url of media directory inside your magento installation
$mediaUrl = Mage::getBaseUrl('media');
Another way to get current url
$urlRequest = Mage::app()->getFrontController()->getRequest();
$urlPart = $urlRequest->getServer('ORIG_PATH_INFO');
if(is_null($urlPart))
{
    $urlPart = $urlRequest->getServer('PATH_INFO');
}
$urlPart = substr($urlPart, 1 );
$currentUrl = $this->getUrl($urlPart);

Hope it Helps! Thanks..

No comments:

Post a Comment