10/06/2010

How to get Current page url in magento

get Current page url in magento is so easy.You can get lots of solution in differnet site.But this one is the sort and best solution for getting Current page url. <?php
echo $currUrl= $this->getUrl('').$_SERVER['REQUEST_URI'];
?>

You can also use the folllowing magento features to get current page Url.

echo $this->helper('core/url')->getCurrentUrl();

2 comments:

  1. $currentUrl = Mage::helper('core/url')->getCurrentUrl()
    or

    $currentUrl = Mage::getUrl('*/*/*', array('_current' => true));
    above code may not work always as expected.
    Better way to find the current url is to use the following code:

    if (!in_array(Mage::app()->getFrontController()->getAction()->getFullActionName(), array('cms_index_noRoute', 'cms_index_defaultNoRoute'))) {
    $currentUrl = Mage::helper('core/url')->getCurrentUrl();
    }
    Source: http://www.blog.magepsycho.com/how-to-find-current-url-in-magento/

    ReplyDelete