简体   繁体   中英

How do I set og:url when a locale is required?

I'm working on a site where the locale is required as part of the URL (eg http://example.com/content/locale ).

If you don't enter a locale (eg http://example.com/content ) you're shown an error page and asked to choose a value from a list.

For most external sites we just omit the locale and let the user choose, however, for Facebook this causes the crawler to scrape the error page.

If we include each locale as a separate og:url this would mean thousands of objects created for each page (as we support that many locales) and potentially hundreds of thousands for the site.

Does Facebook allow such large numbers of og:urls for a domain?

Is there a better strategy I can use?

Facebook expects caninical urls to not directly include a locale code. Including some locale code in the URL will mean you have different objects in the graph, one for each locale.

Instead, create urls which don't include the locale code. On each of your other user-visible urls which do include the locale code, add an og:URL tag that points to the canonical URL without the locale code in it.

On the canonical URL, when Facebook makes a request, look for the useragent string. It if contains "facebookexternalhit" then return HTML and og markup for Facebook to read. If it doesn't, you can serve a 302 and redirect the user to the URL which represents the object in their language.

See FB's open graph internationalization docs for more on how to handle multi-locale objects

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