Magento already have a canonical tool for products and categories ... how does this work with multi stores?
It does not currently have this ability out of the box, so you will need to set this up with an extension. There are many ways you could go about this, but the way I would do it is to modify rel="canonical"
links when they get added.
In my new or modified extension I would extend Mage_Page_Block_Html_Head
and override the method addLinkRel()
to do something like this:
class My_Page_Block_Html_Head extends Mage_Page_Block_Html_Head
{
/**
* Add Link element to HEAD entity
* Overridden to support new canonical cross domain feature.
*
* @param string $rel forward link types
* @param string $href URI for linked resource
* @return Mage_Page_Block_Html_Head
*/
public function addLinkRel($rel, $href)
{
if ($rel == 'canonical' && $ccd = Mage::getStoreConfig('design/head/canonical_cross_domain')) {
$href = preg_replace('/(https?:\/\/)[^\/]+(\/.*)/', "$1$ccd$2", $href);
}
return parent::addLinkRel($rel, $href);
}
}
For this to work as intended, I would need to insert value(s) into the core_config_data
database table. This can be done manually, or even better, in my extension I could set up a new field in the admin configuration section General / Design / HTML Head. I won’t walk through that here since it is just a nice touch. The values to add would be something like this:
INSERT INTO core_config_data
(scope, scope_id, path, value)
VALUES
('stores', STORE_ID_FOR_DOMAIN2, 'design/head/canonical_cross_domain', 'domainname1.at'),
('stores', STORE_ID_FOR_DOMAIN3, 'design/head/canonical_cross_domain', 'domainname1.at');
Now anytime Magento is adding the standard rel="canonical"
links where it normally would, it will first check if there is a cross domain configured for the current store view and substitute in that domain name instead of the current one.