1

When I type in udacity.com in my web browser, it automatically loads https://in.udacity.com

How does this work?

Does the udacity.com machine redirect all requests coming from IPs belonging to India to in.udacity.com using HTTP REDIRECT 301?

3

Udacity uses Cloudflare as a proxy to their actual servers. Any request to https://www.udacity.com will first go to Cloudflare and will then be redirected to the appropriate domain for the geolocation of the origin.

Check the response of:

curl -iv https://www.udacity.com

It's therefore the IP address from which your location can be identified. Cloudflare offers this service — it will add a geolocation header to any request, which the Udacity servers then use to determine which domain to redirect you to.

This method of determining the location is not always precise and may result in false positives, particularly if you are using a VPN provider. Also, it's rather slow depending on how you look up the geolocation. A provider like Cloudflare can do it relatively fast, as they process lots of requests and can cache the information, so it does not add up to the request time. For your small-business website, I would not recommend using the IP to determine the user's location.

The redirect is not permanent, by the way, as you might change countries. So it does not make sense to always redirect you to a specific subdomain. Instead it uses a 302 Found directive, which is temporary.

Another method of redirecting the user based on their location would be to check the Accept-Language header of the browser, which specifies the client locale. The locale may be, for example, fr-CH, which says that you're preferring French, with a Swiss locale (they speak French in Switzerland, but it's subtly different from the French they speak in France, hence the need to differentiate). This, however, is also not always reliable — I have all my software set to American English, and this regularly makes websites think I'm based in America. Here, a geolocation-based approach would be more reliable.

0

There is a HTTP header called "Accept-Language" in the request your browser sends to the server which tells what language you prefer and that information can be used on the server to redirect you to the appropriate site regardless your IP address.

Determining your location based on your IP address (usig GeoLocation databases) could be an another solution, however those databases are usually not 100% accurate.

  • In either case, is the redirection to different URL due to HTTP REDIRECT 301? – karthik ts Jul 17 '18 at 6:45
  • @karthikts No, use curl -iv https://www.udacity.com to see the actual response — it's a 302 response. – slhck Jul 17 '18 at 6:49
  • Udacity is not using the Accept-Language parameter. You can try that for yourself by setting a different one—it's using the IP address instead. – slhck Jul 17 '18 at 6:50

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.