I tried for products and it works fine but for categories I can't remove canonical but I can add a new one.
The problem is that in html code I find 2 different canonical urls.
I used this code in category design field:
<reference name="head"> <action method="removeItem" block="head"> <item>link_rel</item> <name>https://www.mysite.com/produttore/birra-menabrea</name> </action> <action method="addLinkRel" translate="title"> <rel>canonical</rel> <href>https://www.mysite.com/birra-menabrea.html</href> </action> </reference>
I get:
<link rel="canonical" href="https://www.mysite.com/produttore/birra-menabrea" /> <link rel="canonical" href="https://www.mysite.com/birra-menabrea.html" />
I tried also on a clean magento v1.9.3.4 installation and it doesn't work.
Solved! Go to Solution.
I don't think it would have stopped it from working but you don't need the block attribute on the action.
It should be:
<reference name="head"> <action method="removeItem"> <type>link_rel</type> <name>https://www.lacompagniadelcavatappi.com/produttore/birra-menabrea</name> </action> </reference>
<reference name="head"> <action method="removeItem"> <type>link_rel</type> <name>https://www.lacompagniadelcavatappi.com/produttore/birra-menabrea</name> </action> <action method="removeItem"> <type>link_rel</type> <name>https://www.lacompagniadelcavatappi.com/produttore/birra-menabrea?___SID=U</name> </action> </reference>
I don't think it would have stopped it from working but you don't need the block attribute on the action.
It should be:
<reference name="head"> <action method="removeItem"> <type>link_rel</type> <name>https://www.lacompagniadelcavatappi.com/produttore/birra-menabrea</name> </action> </reference>
<reference name="head"> <action method="removeItem"> <type>link_rel</type> <name>https://www.lacompagniadelcavatappi.com/produttore/birra-menabrea</name> </action> <action method="removeItem"> <type>link_rel</type> <name>https://www.lacompagniadelcavatappi.com/produttore/birra-menabrea?___SID=U</name> </action> </reference>
Adding __SID at the end of the url removes the canonical from category page. You don't need to do this on a product page.
Many thanks for the solution.