Home » Magento

Magento: Get current Url of the page

23 November 2009 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

email

php magento mukesh chapagain

Get New Post by Email
RSS Feed Subscribe RSS Feed
  • jazkat

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

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

  • http://haijerome.wordpress.com Jerome Dennis D

    Thanx a lot !!! Its very handy !!!

  • http://sportsmarketingstrategy.com gavin allinson

    Is it possible to export a list of all the urls form in my magento site so that I can then do social bookmarking and other seo related activities on them?

  • Pingback: Magento – Alcune variabili molto utili relative all’URL | Bisonte_biscottato

  • Pingback: Get Media Url, Get Current Url, Get Skin Url, Get JS Url, Get Store Url , Get Base Url in Magneto | DiezArticles

  • http://www.facebook.com/AuVuongLe Chinsu Man

    Hi Mukesh,

    I did that, but i cant get url current on footer (…page/html/footer.phtml ). only flush cache in Admin control panel…this is ok…
    Please, help me
    Thanks a lot!

  • http://www.facebook.com/Bravehartk2 Marcel Lange

    This is much easier I think:

    Mage::app()->getStore()->getCurrentUrl(false)

  • thedotwriter

    $this->helper(‘core/url’)->getCurrentUrl()

    should be replaced by :

    Mage::helper(‘core/url’)->getCurrentUrl()

    Like that you’re sure not to get a white screen of death when you are using it in the wrong context ; )