Home » Magento

Magento: Get current Url of the page

23 November 2009 21,613 views Popularity: 44% Share/Bookmark

email

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

Related posts:

  1. Magento: How to check if current page is homepage?
  2. Magento: Convert Price from Current Currency to Base Currency and vice-versa
  3. Magento: Get current and parent category
  4. Magento: Easily add breadcrumbs to any page
  5. Javascript: How to get current URL without Query string?
  6. Magento: Solution to “Error: 404 Not Found” in Admin Login Page
  7. jQuery: Grey out background and preview image as popup
  8. Magento: How to change default page layout?
  9. Magento: Set/Change page layout, title tag, meta keywords and description
  10. How to show child page (sub page) list in parent page in wordpress?
  • 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?

  • http://www.biso.it/blog/2011/01/13/magento-alcune-variabili-molto-utili-relative-allurl/ Magento – Alcune variabili molto utili relative all’URL | Bisonte_biscottato

    [...] Se lo store in modalità HTTPS $isSecure = Mage::app()->getStore()->isCurrentlySecure(); Il codice di due lettere della lingua dello store attuale. (it, en, fr, etc…) $locale = substr(Mage::app()->getLocale()->getLocale(),0, strpos(Mage::app()->getLocale()->getLocale(),’_')); Il tipo di controller della pagina (tracking, accout, page, catalog, etc…) $controller_name = Mage::app()->getRequest()->getControllerName(); Fonte: Magento: Get current Url of the page [...]

  • http://www.diezarticles.com/others/get-media-url-get-current-url-get-skin-url-get-js-url-get-store-url-get-base-url-in-magneto/ Get Media Url, Get Current Url, Get Skin Url, Get JS Url, Get Store Url , Get Base Url in Magneto | DiezArticles

    [...] js directory inside your magento Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS); Read More : http://blog.chapagain.com.np/magento-get-current-url-of-the-page/ VN:F [1.9.8_1114]Please Wait…Rating: 0.0/10 (0 votes cast)Print FriendlyFacebook [...]

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