Block a country using mod_geoip

Do you have a list of countries that you want to block access to your site?  Have you tried adding IP numbers into your .htaccess file only to generate a HUGE .htaccess file and a neverending stream of IP numbers?  How about using mod_geoip!!

mod_geoip is a module that can be compiled into Apache on build.  Generally shared hosting providers will not have this module loaded, however if you are on a VPS or a Dedicated Server you can compile this module into Apache.

Then just do the following

Edit your .htaccess file

# Add more countries here
Deny from env=BlockThese

A full list of 2 digit country codes can be found here:

The above listed in the example are "CN = China" and "TR = Turkey"

You could also just reverse the .htaccess to make it ALLOW and enter US or UK as the country code.

  • 3 Usuários acharam útil
Esta resposta lhe foi útil?

Artigos Relacionados

301 Redirect for All Domains

So you've purchased a ton of domains to park on your main account, but you don't want Google to...

301 Redirect from non-www to ww -- Without Looping!

So - you want to improve your search engine rankings, and SEO experts are telling you that Google...

Hotlink protecting image.php and GD images

So you've enabled cpanel's hotlink protection, but those bandwidth theives are still attacking...

How do I redirect a page or folder?

I have removed a file from being on the website and would like to forward people who were looking...

How to block an IP number

A user is accessing our website and we'd like to block this user as they continue to submit...