apache-mod_geoip
This is an old post from my previous blog. I'm not sure if the information here is relevant for the latest versions of Apache, GeoIP, etc. Here is the original post:
I had to implement http redirection to pages in different languages, based on visitors' geographic location. E.g. if you are in Germany, Bulgaria or France - you are redirected to a page in German, Bulgarian or French. Everyone else is redirected to the English content. To accomplish this I used mod_rewrite and GeoIP. GeoIP is a product of MaxMind. They provide free database, but the updates for it are payed. I don't remember the exact price, but it was really affordable. MaxMind has Apache module - mod_geoip. It is installed with GeoIP's C API - both are available at their website. API compilation process is straightforward. In order to compile the Apache module you should do this:
Where:
-I/usr/local/include - the directory where GeoIP.h is located
-L/usr/local/lib - the directory where libGeoIP is installed
Next you should configure Apache itself. Here is a part from my configuration file:
%{ENV:GEOIP_COUNTRY_CODE} is a variable, which contains country's two letter according to ISO 3166-1.
More information about mod_rewrite and regular expressions can be found here:
mod_rewrite documentation on Apache web site
The book Mastering Regular Expressions of Jeffrey Friedl
The book The Definitive Guide to Apache mod_rewrite of Rich Bowen
Comments
Comments powered by Disqus