Site selection based on IP address

What is it?

Many big multi-national websites use this technique. If they have different country specific websites, when a user lands on any one of the sites, they are redirected to the specific site for their country.

Why do this?

If you have build a site that specifically targets a geographic region (usually by country), then you probably want your users to access this site instead of any of your other websites.

How is this done?

Most browsers pass some information to sites along with the request for a web page. One of these pieces of information is your computer's IP address. This address is usually specific to your geographic location. Your IP address is compared to a database mapping IP address's to geographic locations and then your browser is redirected to your country specific website.

Example

A good example of this is if you are in a country other than the US and browse to Google.com. You will be redirected to a country specific site (i.e. google.ca).

Technical details

  1. First, set up a way of mapping a users IP address to a geographic location.
    • The easiest for many is to find a web service to call on the fly with an IP address and be passed back the location.
    • The other method is to set up a database with these mappings on your own server. There are a few free options for this information or if you want more accurate information it best to buy this information.
  2. Next, set up the redirect.
    • Anyone running their own apache webserver should use this approach. In your http.conf set up a transhandler. In the transhandler, perform the lookup on the users IP address and if they should be redirected to one of your other websites, redirect the user their specific geotargeted website.
    • If you are building a new site and have can set up a .htaccess file or already redirect all requests through a central file, use this method. Send all requests to a central file. At the start of the file, perform the lookup and if necessary, redirect the user.
    • All other users will need to create a common lookup module and call it at the beginning of every file on your server.

Caveats

You need to handle users who want to access one of your websites that does not match their IP address geographically. There are a couple of approaches to do this.

  • The simplest is to add a link(s) to your other websites somewhere on each of your websites. Then before you do the IP address check, check to see if the referring url is from one of your other websites. If so, set a cookie, and let the user stay on the site.
  • Another approach would be to log all entries on a site. If a user comes back to one of your geographically targeted websites after being redirected, set a cookie, and let them stay.
  • Disable browser page caching on the redirected url or else users won't be able to make it back to the original website.

Contact us to learn more about having this set up on your website(s). You can also visit our website development services page for more information about the services we offer.

Reply

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options