We are aware of a potentially service impacting issue. Learn more

Usage: mod_geoip Print

  • 13

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:


Was this answer helpful?

« Back