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

For any kind of assistence or question please contact support[at]mellowhost.com

  • 22 brukere syntes dette svaret var til hjelp
Var dette svaret til hjelp?

Relaterte artikler

Binary Location of FFMPEG!

[Applicable for all of our servers] If you are trying to use FFMPEG, then you would be looking...

Binary Location of Required Modules to play embedded Video!

[Applicable for the server name All Mellowhost Servers] Mplayer /usr/local/bin/mplayer Mencoder...

ImageMagick Location

Imagemagick binary/convert is located under /usr/binConvert file: /usr/bin/convert

PHPShield Error

Please take a look at the following url: http://phpmotion.com/forum/index.php?topic=74.0 If you...