Blocking Specific User Agents

|
I came across a situation recently where a site was getting hammered by a couple of different ip addresses. The one thing they had in common was that they were all using the same User Agent, VoilaBot in this case. Instead of blocking each IP using IPTables, the following was added to the .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} VoilaBot
RewriteRule .* - [F,L]
Any client with "Voilabot" in the User Agent now gets a forbidden page.

If you want to ban multiple User Agents, you can do the following:
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} UserAgent1 [OR]
RewriteCond %{HTTP_USER_AGENT} UserAgent2
RewriteRule .* - [F,L]

About this Entry

This page contains a single entry by Niall Donegan published on October 11, 2007 12:00 AM.

Canonical Urls With Mod Rewrite was the previous entry in this blog.

Redirect According To The User's Language is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.34-en