You must be wondering we can simply use:
$currentUrl = Mage::helper('core/url')->getCurrentUrl()
or
$currentUrl = Mage::getUrl('*/*/*', array('_current' => true));
in order to find the current URL.
But it doesn’t always work as expected.
Try to use the above code in a page which has some missing CSS, js, images, etc.(You can use Firebug in order to find such error which is a so-called Network error.). You will see that the above code captures the URL for missing file(js, CSS, images, etc.) which is obviously not the required current URL.
You can simply fix the above error by using the following code:
if (!in_array(Mage::app()->getFrontController()->getAction()->getFullActionName(), array('cms_index_noRoute', 'cms_index_defaultNoRoute'))) {
$currentUrl = Mage::helper('core/url')->getCurrentUrl();
}
Cheers!