CentrioHost 24/7 Live Support

 

Usage: mod_geoip

We have seen loads of our clients use .htaccess to block different type of country (Using Ip ranges). There are several reasons for doing it. Most of the cases, Webmasters block country traffic for abusing Bandwidth, Protecting Google Adsense Smart Pricing etc. Although, .htaccess blocking works, but it creates extra loads on the server. As we are not intended to block or suspend anyone's account for such thing, thats why we have implemented mod_geoip on the server and suggest our clients to block traffic (If required) using mod_geoip instead of IP range blocking using .htaccess

mod_geoip needs to be implemented using .htaccess, it is also configurable using PHP. Here we will describe some examples to block countrywise traffic using mod_geoip and .htaccess (Without IP range)

To block traffic other than US, UK and Canada use the following code:


RewriteEngine On
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} !(US|GB|CA)$
RewriteRule ^(.*)$ block.php [NC,L]

This code is negating for the traffic of US, GB and CA and redirecting them to block.php, you can change it to different site like, to redirect traffic to google.com just replace block.php to http://www.google.com

To block certain traffic you can use a code for example:


RewriteEngine On
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} (CN|IR)$
RewriteRule ^(.*)$ block.php [NC,L]

This code will block the traffic from China and Iran, then redirect them to block.php. block.php is also replacable with a website address. But it must be included with "http://"

Country code is Important here, as country code needs to be used to block the traffic from countries. You can find the country code located http://www.maxmind.com/app/iso3166

Add to Favourites  Add to Favourites    Print this Article  Print this Article

Was this answer helpful?


Hosting Partners
Wildcard SSL Certificates