I'm running single Magento 1.7 installation with 2 store views. I have two domains which are search engine optimized for Ireland and UK. Since content is very similar I would like to use rel="alternate" hreflang="XX":

<link rel="alternate" hreflang="en" href="http://domain.ie/" />
<link rel="alternate" hreflang="en-gb" href="http://domain.co.uk/" />

Is there a easy solution / plugin that will allow me to choose relation between those two store views for product / category / text page?

  • Do you have your url keys common across sites or you have a different URL key for each store view? Commented May 17, 2013 at 11:28
  • I used to have different ones, but as I answered, I'm going to use same on on both pages. Commented May 17, 2013 at 14:12

3 Answers 3


Whereas anchor tags in Magento are built piecemeal in templates, there is no central, easy way to do this. Sorry. The only centralized approach of which I can think is to observe the controller_front_send_response_before and execute a complex preg_replace() to rewrite all anchor tags - but you're likely to have a bad time with catching all links.

However, it seems a better approach may be to use sitemaps, at least as far as Google is concerned: http://support.google.com/webmasters/bin/answer.py?hl=en&answer=2620865

Credit to http://www.rimmkaufman.com/blog/advanced-international-seo-rel-alternate-hreflang-x/13122011/ for the sitemap information.

  • Thanks for reply. Creating complex preg_replace() in controller_front_send_response_before is much too complicated. I'll spend too much time on it ;-) Commented May 16, 2013 at 15:57

Since one website is doing well in search results, and second does not rank at all, that's what i figured out:

  • At text pages you can use Layout Update XML (same sa canonical URLs)

<reference name="head"><action method="addLinkRel"><rel>canonical</rel><href>http://www.yoururl.com/goes/here</href></action> </reference>

  • I'll use same products urls at both pages and 301 old entries

  • default actions ( as register / checkout ) have same request uri, so there is no need to change it

  • if product is not available in second store I'll redirect ( 301 ) request to homepage

  • by default header displays rel="alternative" with switched domain address

  • I'm not sure whether "canonical" is really the way to go over "alternative". Anyway, if you need to specify an alternative with a hreflang, you can use: <action method="addItem"> <type>link_rel</type> <href>http://www.yoururl.com/goes/here</href> <params>rel="alternate" hreflang="en-gb"</params> </action> Commented Sep 19, 2013 at 9:16

I have created this in the past. I do not have the code anymore but here is an idea and little code snippet to get you started.

You can observe 'controller_action_layout_generate_blocks_after'


Then in your observer method find the relevant rewrite and add the link to head block:

public function createAlternateLinks($observer) {

        $headBlock = Mage::app()->getLayout()->getBlock('head');
        $helper = Mage::helper('example');

        if ($headBlock) {
            foreach ($Mage::app()->getStores() as $store) {
               //this will be your logic for fetching the urls, I suggest using the current urls or registry ('current_product','current_category') to get the product, category 
               //and then using rewrites finding the relevant url for other store view
               $url = $helper->getAlternateUrl();

               //this will be used for hreflang but feel free to omit it or simply use store locale
               $area = Mage::helper('your_module')->getArea($store->getId()); 

               // add the alternate link
               $headBlock->addLinkRel('alternate"' . ' hreflang="' . $area, $url);


        return $this;

Then you can get alternate urls using url rewrite model. For example for product page url you can use this

 public function rewrittenProductUrl($productId, $storeId) {
    $coreUrl = Mage::getModel('core/url_rewrite');
    $idPath = sprintf('product/%d', $productId);

    return $coreUrl->getRequestPath();

So really all you have left to do is stick everything together and create the logic for getAlternateUrl using the registry and url rewrites.

Let me know if something is unclear and needs clarification.

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.