Home » Magento

Magento: Get current Url of the page

23 November 2009 2,371 views One Comment Popularity: 25% Share/Bookmark

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

From Mukesh Chapagain's Blog | Post Magento: Get current Url of the page

Related posts:

  1. Magento: Get current and parent category
  2. Magento: Easily add breadcrumbs to any page
  3. Magento: Get width height of image using Varien_Image class
  4. Magento: Create Watermark Image
  5. Magento: Crop image

One Comment »

  • jazkat said:

    This worked for me:
    $currentUrl = Mage::helper(‘checkout/url’)->getCurrentUrl();

    as
    $this->helper(‘core/url’)
    returned as undentified method in my controller.

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.