kieranbarnes do you know where your towel is?

Block Countries in Apache

Posted on November 18, 2008

Assuming you have mod_geoip installed in apache we can block certain countries in 6 lines of code.

I had a client who was experiencing an inhumane amount of spam on their phpBB forums, which are notorious for bot attacks. Luckily this forum was geographically specific - so we can block all the countries we aren't interested in.

Here's the .htaccess code I put in the forums sub-directory


# START Block Countries

RewriteEngine On
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} !^(GB|US)$
RewriteRule ^(.*)$ http://www.some-page-outside-the-forum-directory$1 [L]

# END Block Countries

This code will allow only Great Britain and the United States into the forum directory, any other country will be redirected to a page describing why they aren't allowed instead of simply blocking them.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Related posts:

  1. mod_geoip Revisted including stopping spam in phpBB 2
    I've recently moved a client's forum onto a new cPanel server, previously it was on...
  2. Apache, JungleDisk and Port 80
    I was tearing what little hair I have trying to solve a very strange bug...
  3. SEO Friendly URLs for CubeCart in Windows
    I have a client hosting CubeCart on a Windows server. Unfortunately the built in Apache...
  4. Redirecting WordPress index.php to root
    If you check the Page Rank of http://bloke.org against http://bloke.org/index.php, which are both, to a...
  5. NTLM Authentication (Active Directory) on Apache (Linux)
    Here is a quick guide to enabling NTLM authentication for Apache 2. I generally use...

What this article useful to you?



Let me know, buy me a beer!
Alternatively, if you're feeling impecunious, you may like to subscribe to my RSS feed, or see other articles in the Apache, Geeky category.

Filed under: Apache, Geeky Leave a comment
Comments (0) Trackbacks (1)

Leave a comment