Read the other articles

How Does Geo-Based Redirection Work?

How Does Geo-Based Redirection Work?

Our mission here at geo.ipify.org is to educate our clients on how they can make the best use of our software. Our clients often ask us as an IP intelligence provider for tips on how to implement IP geolocation technologies to attain specific goals. One question that we often get is concerned with geo redirection.

Geo redirection is a personalization technique wherein users see content that corresponds to their locations. It involves the use of location data, specifically, geolocation information derived from IP addresses.

Over the years, the need for geo redirection has become more significant as companies do their best to identify opportunities in new markets. Consumers tend to be more receptive to a brand that speaks their local language or offers them the choice to view location-based content.

This post provides site owners with insights into how to apply geo redirection from a marketing and web development perspective. We’ll also recap some best practices so that you can remain compliant with Google’s guidelines on redirects.

What Are Google’s Thoughts on Redirection?

As we previously wrote, Google wants site administrators to treat bots just like any other website visitors. Google has always asserted that if a bot appears to come from the U.S., then you should show it the same content as you would human visitors from the country, and the other way around.

There are exceptions to this rule, however. Bots don’t have to see some types of content, such as splash pages, forms, login pages, or interstitial ads. After all, those don’t need to be indexed. Redirection practices, even those bordering on the gray-hat territory, won’t get penalized as long as you have a legitimate purpose for it.

How Do You Implement Geo Redirection?

Users can use the following methods to achieve geo redirection:

  • Using PHP or JavaScript (JS): If you don’t have database access, you can obtain the IP address of visitors manually by adding a PHP or JS code to your source code. An example variable, $_SERVER['REMOTE_ADDR’], allows you to get the IP address of a user viewing a particular page. Here’s the complete script for this function (source: CODEX WORLD):

    function getUserIpAddr(){
        if(!empty($_SERVER['HTTP_CLIENT_IP'])){
            //ip from share internet
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
            //ip pass from proxy
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        }else{
            $ip = $_SERVER['REMOTE_ADDR'];
        }
        return $ip;
    }
    
    echo 'User Real IP - '.getUserIpAddr();

    You can view tutorials here: tutorial 1 and tutorial 2. In addition, you can use the IP Geolocation API that retrieves information from our database. You can view sample codes here for JS, as well.

  • Using .htaccess: Make sure you have .htaccess privilege by contacting your host to be able to modify it. There are two ways to apply a redirect through the .htaccess configuration file. One is through a 301 redirect or by using the mod_rewrite module.

    301 redirects are important in search engine optimization (SEO), as it allows users to pass on while preserving the link equity of webpages. To apply a 301 redirect, find the .htaccess file in the Apache document root. Edit the file using your text editor and add the following commands:

    To redirect a page, use:

    RedirectPermanent /international-homepage.html https://www.domain.com/users-country.html

    To redirect an entire domain, use:

    RedirectPermanent / https://www.internationalhomepage.com/

    Apache server also has a mod_rewrite module for mapping a universal resource locator (URL) to another file or domain. When the mod_rewrite module detects a bot’s IP address, the user agent loads a separate page from the default one. You may refer to the mod_rewrite module’s documentation here and redirecting directives here.

  • Using plugins or third-party tools: There are a variety of open-source plugins and APIs that you can use to redirect users based on IP identification. With this method, users don’t have to select their native language or country from a switching module. Instead, they are redirected automatically to an internal or external page as specified through the plugin. In most instances, all plugin users have to do is input the URL for that or tick some boxes.
  • Using tags and sitemaps: Tags like rel= “alternate” hreflang= “x” and rel=” canonical” tells Google which homepage is your site’s preferred language or country versions for foreign visitors. Such tags also tell Google which pages should have more weight and thus show up in search results. When generating a sitemap for your site, ensure that an entry for each language version is listed in it. Read Google’s guidelines for hreflang and sitemaps here.

Examples of Geo-Based Redirection Using IP Geolocation

Users should not confuse geo redirection with geofencing or geotargeting, though. While these terms are all considered geolocation marketing techniques, they differ in delivery and connotation.

Geofencing focuses on proximity marketing using virtual perimeters, sensors, or beacons. Geotargeting, meanwhile, is more associated with local pay-per-click (PPC) ads, but it is semantically the same as geo redirection. However, geo redirection is a more commonly used term for website redirection than the other two.

Here are some common examples of how companies incorporate geo redirection:

  • Geo-redirecting overseas visitors to content from the same website: When you search for the British Broadcasting Corporation (BBC) website, you’ll notice that the most prominent link on top of the search results is https://www.bbc.co.uk. Non-U.K. readers accessing this link will initially land on the U.K. site, giving them a glimpse of the U.K.-centric stories. The page then refreshes in a fraction of a second to load the international version of the website https://www.bbc.com.
  • Geo-redirecting visitors to content specific to their city or state: Eventbrite.com, a popular events listing site, would show page content tailored to its users’ locale.
  • Geo-redirecting visitors based on their preferred language: Non-U.S. residents who set their user agents to English see the English language version of the site. When they visit the American Airlines website, https://www.aa.com, for example, they are redirected to https://www.aa.com/homePage.do?locale=en_US.
  • Geo-redirected email campaign links: This technique works the same way. US-based email users who click on a link from an email they received would land on the U.S.-targeted landing page of a site (assuming that page exists and is set up for that purpose).

Geo redirection is a great way to enhance your users’ site experience, decrease bounce rates and increase conversions. You can choose to write your program to accomplish the technique or rely on a host of free and paid tools for worry-free implementation.

To ensure the accuracy of user redirects, it helps to integrate an IP intelligence tool like IP Geolocation API into your geo redirection tool. Various firms recognize our IP Geolocation Database for its accuracy. Contact us at [email protected] for an obligation-free consultation.

Read the other articles
Try our IP Geolocation API free of charge
Get started
Have questions?

Or shoot us an email to