Canonical url and og:url for multilanguage site
Asked Answered
N

1

6

I read a lot about these subjects and I know that no solution is perfect to handle a multilanguage site. I'm using different folder to serve content for different languages, thus I have www.example.com/en, www.example.com/es, etc.

When a user visit the site for the first time at www.example.com I choose the best matching language from Accept-Language HTTP header and redirect it to the most appropriate page using en version if no language match. For this reason there is no real page at www.example.com and it always generates a redirect.

This is working very well for both users and search engines however there is a flaw in this approach, likes are spread across different languages, I want all of them for www.example.com

If I set og:url to root page FB crawler complaints about redirect loop because it goes from www.example.com then it's redirected to www.example.com/en which has og:url set to www.example.com. I want to keep likes unified i.e. a like for www.example.com/es and a like for www.example.com/en should both count for main domain.

My current solution is to modify the redirect code in this way: when user agent is facebook never redirect when www.example.com is requested. Use default locale or locale requested by FB with fb_locale param.

I've also added locale open graph tags to tell FB about different locales for my page.

Finally I kept the canonical url tag with the locale portion because each language is serving its own content in this way search engines should be aware of that. This is (more or less) the head section of the home page

<meta content="website" property="og:type" />
<meta content="http://www.example.com/" property="og:url" />    
<meta content="en_US" property="og:locale" />
<meta content="es_ES" property="og:locale:alternate" />
<meta content="fr_FR" property="og:locale:alternate" />
<link href="http://www.example.com/en" rel="canonical" />

In this way everything seems to work and like count are shared across all languages. I'm only getting a warning by facebook debugger

Mismatch og:url and canonical url: og:url tag in the header is not the same URL as rel='canonical' link in the html.

Is this setup correct? Will I have any issue with this markup?

Similar question but he wants likes per country.

Nicotinism answered 6/8, 2015 at 16:47 Comment(2)
A warning is just that – a warning. You are alerted here that those two values don’t match, and that you should look into that. However, since you deliberately chose to have it that way, no looking into it required actually. The debug tool tells you which URL Facebook considers to be the “final” one for the object – and if that is the one you want, then there’s no need to worry.Ahearn
@CBroe thanks. It's what I thought. Do you see any other issues in that markup? e.g. with search engines.Nicotinism
P
1

On a SEO purpose, i would recommand to use href_lang and those kind of syntax: For example with fr and en language when you're on the french version

<link rel="canonical" href="http://www.yourdomain.com/fr" />
<link rel="alternate" href="http://www.yourdomain.com/fr" hreflang="fr-FR" />
<link rel="alternate" href="http://www.yourdomain.com/en/" hreflang="en-US" />
Pavyer answered 23/1, 2020 at 13:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.