Magento 1.9 URL – How to Remove Duplicate Parameter

magento-1.9parameterurl

In my custom module I have passed parameter in URL like this:

<?php $currentUrl = Mage::helper('core/url')->getCurrentUrl(); ?>
<a href="<?php echo $currentUrl .'?alpha='. $letter ;?>"><?php echo $letter; ?></a>

The problem is that I have used this parameter to filter collection and the result is returned to the same page, everything is working fine. But from result page when another parameter is selected URL became like this:

www.mydomain/category.html?alpha=D?alpha=J

Is it possible to remove the duplicate parameters?

Note: need to remove only duplicates not the other parameters.

Best Answer

Instead of getCurrentUrl() you can use the special parameter _current for getUrl() and then override the "alpha" parameter:

<?php $url = Mage::getUrl('', ['_current' => true, '_query' => ['alpha' => $letter]); ?>
<a href="<?php echo $url ;?>"><?php echo $letter; ?></a>
Related Topic