In Magento, I use below codes as required to get the Current Url and pages. I hope this will help you to find current url in your magento ecommerce website. Below is the first code that will return full Magento's current Url.
<?php $currentUrl = $this->helper('core/url')->getCurrentUrl(); ?>
<?php $current_page = ''; /* * Check to see if its a CMS page * if it is then get the page identifier */ if(Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms'): $current_page = Mage::getSingleton('cms/page')->getIdentifier(); endif; /* * If its not CMS page, then just get the route name */ if(empty($current_page)): $current_page = Mage::app()->getFrontController()->getRequest()->getRouteName(); endif; /* * What if its a catalog page? * Then we can get the category path :) */ if($current_page == 'catalog'): $current_page = 'categorypath-' . preg_replace('#[^a-z0-9]+#', '-', strtolower(Mage::registry('current_category')->getUrlPath())); endif; ?>
Other Related useful shortcuts:
Get Magento Url including index.php if not rewrited.
e.g. http://w3tut.org/index.php/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
Get Magento Media Url
e.g. http://w3tut.org/media/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
Get Magento Skin Url
e.g. http://w3tut.org/skin/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
Get Magento Store Url
e.g. http://w3tut.org/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
Get Magento Js Url
e.g. http://w3tut.org/js/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
Get Home URL
$magento_home_url = Mage::helper('core/url')->getHomeUrl();
Get not secure Skin URL:
$image = $this->getSkinUrl('images/magento-image.jpg');
Get secure Skin URL
$image = $this->getSkinUrl('images/magento-image.jpg', array('_secure'=>true));
Magento Syntaxes to use in CMS Content.
Get SKIN URL
{{skin url='images/magento-image.jpg '}}
Get Media URL
{{media url='/magento-image.jpg'}}
Get Store URL
{{store url='magento-page.html'}}
Get Base URL
{{base url='magento-page.html'}}
Useful code in magento development
Get full Skin Url inside code
e.g. http://w3tut.org/skin/frontend/default/default/
Mage::app()->getLayout()->getBlock('head')->getSkinUrl();
Read Here for: Magento Get Current Category
Aumit posted on - Tuesday 20th of July 2010 03:52:54 AM
zuloo posted on - Tuesday 5th of October 2010 04:00:41 PM
str_replace($this->getUrl(),"",$this->getUrl('*/*/*', array('_current' => true, '_use_rewrite' => true)));
you may add some more params, to still get query-params and stuff...
ywcr posted on - Tuesday 12th of October 2010 07:22:10 PM
<?php $currentUrl = $this->helper('core/url')->getCurrentUrl(); ?>
Magento Services posted on - Wednesday 15th of December 2010 03:50:29 AM
glee kim posted on - Thursday 28th of April 2011 03:21:44 AM
rahul posted on - Saturday 23rd of July 2011 05:19:49 PM
Gopu posted on - Friday 6th of January 2012 05:11:12 AM
MagentoX posted on - Sunday 8th of January 2012 09:51:32 PM
Daniel posted on - Friday 20th of January 2012 02:25:07 PM
Thanks.