formats

Apache Block By User Agent

Published on June 28, 2011, by + in sysadmin.




Though this is trivial to circumvent, an easy way to block by User Agent with Apache is to use mod_rewrite.

This is rather more useful to deny spam bots, scammers, and other automated tools from poking at your website!


The following rewrite rule gives a 403 Forbidden for example:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} HTTrack
RewriteRule ^.* - [F]

Place this in either your virutalhosts config file, or an .htaccess file.


PS: There is a well known but somewhat dated ‘ultimate’ htaccess blacklist available here which has a compiled list of bots to deny:

http://perishablepress.com/press/2007/10/15/ultimate-htaccess-blacklist-2-compressed-version/

Sweet!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Home sysadmin Apache Block By User Agent