简体   繁体   中英

Magento Multistore Canonical Tag

I got a short question for you. Magento already have a canonical tool for products and categories.

But how does this work with multi stores?

Example:

I have 3 domains.

http://domainname1.at
http://domainname2.de
http://domainname3.ch

All of them have the same content (German language).

when I activate canonical tags for the domainname3.ch the tag looks like:

<link rel="canonical" href="http://dimainname3.ch" />

But I want that domainname2 & domainname3 canonicaltag points to domainname1 where the unique content is located!

Thx!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM