Best Magento practice to get current Url of the page

  • magento get current url
  • magento current url
  • get current url in magento
  • get current url magento

The following code gives you the current url of the page you are:-

$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);

Comments

Leave a Reply

Your email address will not be published.

18 − seven =

Security Code: