title is pretty clear.
My websites consists of both English-written and Spanish-written versions.
You can go to the main site, which is in Spanish, by clicking http://www.chrishonn.com and to the translated version, which is in English, at http://en.chrishonn.com. At the index of each page there is a link (at the bottom) which allow the user to pass from one site to the other.
However, I was wondering, how do big sites like Google, Yahoo!, and other brands' websites to recognize the user's geographical location/IP so that - depending on that - the site's language is adapted (i.e. you are from China and you visit www.google.com, you'll be redirected to www.google.cn).
I have stated on every single page of my website the language:
<meta http-equiv="content-language" content="en">
That example is of course from one of the http://en.chrishonn.com sites, which are in English.
I hope someone can give me a hand.
Thank you (if I missed something, please let me know).
As for Google, your location is determined from your IP address. A request to google.com from outside the US returns an HTTP/1.1 302 Found
which redirects you to your country specific domain.
As also discussed on another post, doing these kinds of redirects can make SEO tricky and complicated. I suggest reading Matt Cutt's article (a Google software engineer) on how Google handles the 302 Redirect: SEO advice: discussing 302 redirects.
Different search engines handle the 302 redirect in a different way. With 302 redirects, you may risk having your original domain ignored by search engines.
If you want to determine your users' location from their IP address, there are many off-the-shelf services which basically map most of the IP ranges to countries. You may want to check:
- MaxMind GeoLite Country
- IP2Location.com
Another popular technique is to parse the Accept-Language HTTP header, which contains information about the user's language preferences. Mainstream browsers allow these language preferences to be modified by the user. You may read more about this technique from:
- Parse Accept-Language to detect a user's language
- W3C - Accept-Language used for locale setting
Rather than detecting the location of IP address (often unreliable due to NAT and proxying) you could check the default language the browser is set to.
There are JQuery plugins to support this, such as http://keith-wood.name/localisation.html, or use server-side code to read the HTTP request header "HTTP_ACCEPT_LANGUAGE" to determine if you want to show the ES or EN site.
some website use IP address-based geo location, some us Accept language header (can be set in the browser). Anyway, from the usability point of view - always allow people to change the language and never display different content on the same IP (google and other search engines doesn't like it and it would be bad from SEO point of view).
These sites often use tools that are generically called "geolocation software".
One of the most popular packages is the free GeoLite Country database offered by MaxMind. This will integrate into your application and provide IP-to-country lookups. With Apache, you will have some environment variables set called GEOIP_COUNTRY_CODE and GEOIP_COUNTRY_NAME.
All your application has to do after that is decide where your user should be or what settings they should have by default based on the country, and redirect or output appropriately.
You can do a GET request to this URL: https://api.teletext.io/api/v1/geo-ip and it will respond with some country information in JSON format. See https://teletext.io/help/geo-location-service for usage.
If you want to implement it yourself: I've set this up by using AWS Cloudfront, Cloudfront adds a header (Cloudfront-Viewer-Country) to your request before it forwards it to the origin server that you can use. Make sure to whitelist the header in your Cloudfront distribution.
I have created cloud distribution and white listed the CloudFront-Viewer-Country header.
But when I accessed object using this distribution I did not see it in request header.