There is a question on stackoverflow, perhaps this is a better place to ask for:
You will need to create an entry in a
layout.xml file to put an additional template in the head section of the page when you are on a category page (this would likely be in a
catalog_Category_view block). You would also probably need a view file as well as a Block object to fetch the URL you want to use (technically you could put that in the view file, but having the block object is more "Magento").
Your layout.xml block would look something like this
<catalog_category_view> <reference name="head"> <block type="canonical/canonical" name="head_url" as="head_url" template="ocaff/canonical/head.phtml" /> </reference> </catalog_category_view>
This block references a
head.phtml file. That file would contain:
<link rel="canonical" href="<?php echo $this->getCanonicalUrl() ?>" />
This calls back to a block object that has a function called
getCanonicalUrl(). In this function you will find and determine what you want the canonical to be. Most likely you want this to be the URL key, but you may have other logic in mind there.