Magento 1.9 – Remove Last Trailing Slash from URL

magento-1magento-1.9url

I am using this code to get the URL of the current page I am on:

<?php $currentUrl = Mage::helper('core/url')->getCurrentUrl(); ?>

Problem is, at the end of the url, there is a slash. How can I change this:

example.com/page/

To this:

example.com/page

Best Answer

Below code has hack But work all time please check and let me know

<?php  
      $my_url = Mage::helper('core/url')->getCurrentUrl();  
         if(substr( $my_url , -1) == '/' ) {
              $currentUrl = rtrim($my_url, "/"); 
       }else{
            $currentUrl =$my_url;
       } ?>
Related Topic