Bringing Location to the Internet

Apache Module

This is an IP2Location Apache Module that enables the user to identify the country, region, city, latitude, longitude, zip code, time zone, ISP, domain name, connection type, area code and weather by IP address. It contains a demo IP2Location IP-COUNTRY BIN database which consists of real data for IP address range 0.0.0.0 to 99.255.255.255. This database contains IP address blocks as key and countries as values. The paid version of IP2Location database covers all IP address ranges. In general, it is more complete, faster and more accurate than using reverse DNS lookups.

Developers can download other sample databases to evaluate other features such as region, city, latitude, longitude, zip code, ISP and domain name using the same Apache module.

Download IP2Location Apache Module (931.55 kB) Version: 5.0.0

 

Installation

Linux/Unix

  1. Download IP2Location C library at here.
  2. Decompress C library.
    tar xvfz ip2location-c-x.x.x.tar.gz
  3. Download and decompress Apache module.
    tar xvfz ip2location-apache-x.x.x.tar.gz
  4. Get into working directory.
    cd ip2location-apache-x.x.x
  5. Start compilation.
    apxs2 -i -a -L /usr/local/lib/ -I ../ip2location-c-x.x.x/libIP2Location/ -l IP2Location -c mod_ip2location.c
  6. Add following lines into /etc/apache2/apache2.conf
    <IfModule mod_ip2location.c>
    	IP2LocationEnable On
    	IP2LocationSetmode <ALL>
    	IP2LocationDBFile <ip2location_binary_db_file_with_fully_qualified_path>
    </IfModule>

Windows

  1. Download IP2Location C library at here.
  2. Decompress C library using 7-zip or other compression tools.
  3. Download and decompress Apache module.
  4. Navigate to ip2location-apache-x.x.x folder.
  5. Edit Makefile.win to change the path for C library.
    IP2LOCATION_CSRC_PATH = C:/ip2location-c-x.x.x/libIP2Location
    IP2LOCATION_CLIB_PATH = C:/ip2location-c-x.x.x/libIP2Location
    APACHE_INSTALL_PATH = "C:/Program Files/Apache Software Foundation/Apachex.x"
  6. Start compilation.
    nmake /f Makefile.win
  7. Copy IP2Location_apache.dll generated to Apache modules directory.
  8. Add following lines into httpd.conf
    <IfModule mod_ip2location.c>
    	IP2LocationEnable On
    	IP2LocationSetmode <ALL>
    	IP2LocationDBFile <ip2location_binary_db_file_with_fully_qualified_path>
    </IfModule>

 

Sample Codes
RewriteEngine On
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^UK$
RewriteRule ^(.*)$ http://www.google.co.uk [L]

 

Sample Database (BIN)

Evaluation version of the database file having limited range of IP address information. You can query all IP addresses from 0.0.0.0 to 99.255.255.255 only.