Home » Magento

Magento: Get current Url of the page

23 November 2009 25,033 views Popularity: 46% 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: How to check if current page is homepage?
  2. Magento: Easily add breadcrumbs to any page
  3. Magento: Convert Price from Current Currency to Base Currency and vice-versa
  4. Magento: Get current and parent category
  5. Magento: Resize Image
  6. Magento: Get width height of image using Varien_Image class
  7. Magento: Create CMS Page & Static Block programmatically
  8. Magento: Solution to “Error: 404 Not Found” in Admin Login Page
  9. Magento: Custom function to resize image proportionally
  10. Javascript: How to get current URL without Query string?
  • 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)