Filtering Visitors to Your Site Base on Country

by admin on September 3, 2010

Using GeoIP Apache API.
Source: http://www.maxmind.com/app/mod_geoip
You need to contact your administrator to install some file ad configure them.

Examples
Redirection with mod_geoip and mod_rewrite
Below are examples of how to perform redirection based on country with mod_geoip and mod_rewrite. This configuration should be added to your Apache httpd.conf or .htaccess file.

======================
Options -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domainname.com [NC]
RewriteRule (.*) http://www.domainname.com/$1 [L,R=301]
SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE HK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE AF BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry
Deny from env=BlockCountry
=======================================

If your site using wordpress platform, you can try this plugin, iQ Block Country.

http://wordpress.org/extend/plugins/iq-block-country

This plugin uses the GeoLite database from Maxmind. It has a 99.5% accuracy so that is pretty good.

Leave a Comment

Previous post:

Next post: