0

When i click on add to compare link on product listing page my url is changing from

magento.com/personal-care/face.html?dir=asc&order=Normal

to

magento.com/personal-care/face.html?dir=asc&order=Normal

And the above link is breaking.

When I am making a small correction in the above url, by changing & to &. Then it is working fine for me.

I also tried RewriteRule ^(.*)&(.*)$ /$1&$2 [L,R=301] in .htaccess but no luck.

3
  • How does the button / link look like on the frontend. Is it an <a> tag with href attribute or is it using a JS function setLocation? If it's the latter I have the answer ready :)
    – Alex Dinca
    May 19, 2017 at 13:42
  • it's in <a> tag, $this->getAddToCompareUrl($_product). May 20, 2017 at 6:07
  • And the link is added in the href tag (href="<?php $this->getAddToCompareUrl($_product) ?>") or inside the onclick tag (onclick="setLocation(<?php $this->getAddToCompareUrl($_product) ?>)")
    – Alex Dinca
    May 21, 2017 at 9:58

3 Answers 3

0

Please try this in .htaccess:

RewriteCond %{QUERY_STRING} ^(.*)&amp;(.*)$
RewriteRule ^(.*)$ /$1?%1&%2 [L,R=301]
2
  • I found solution thank you for your help. May 20, 2017 at 13:22
  • @PratikDhamane your welcome! :) May 22, 2017 at 6:29
0

To overcome this problem i just rewrite app/code/core/Mage/Catalog/controllers/Product/CompareController.php

replaced

$this->_redirectReferer();

with

$refererUrl = $this->getRequest()->getServer('HTTP_REFERER');

$this->_redirectUrl($refererUrl);

in addAction() function.

It seems & is replace with &amp; because of the _getRefererUrl() function in

app/code/core/Mage/Core/Controller/Varien/Action.php

0

RewriteRule ^(.*)$ /$1?%1&%2 [L,R=301] is taking to index.php always. If I'm on the product page URL, I need to keep it, so for example:

www.domain.com/product.html?a1=v1&a2=v2

is taking me to

www.domain.com/index.php/?a1=v1&a2=v2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.