Comment spam and mod_rewrite
In my never-ending quest to fight comment spam in my weblog I have been closing off older entries to comments. This works remarkably well, comment spam has come down significantly. Unfortunately, the attempts have not. A simple sampling of my log shows over 200 POST requests today to entries with turned off comments. Obviously, a spam bot. This begs for a new rewrite rule. Granted, the comments were not posted, but it annoys me regardless.. so from now on, if you wish to make a POST request to my server there is a new condition.. you need to be referred from my domain.. Turned off the referer in your browser? Bummer.. you can't post comments.
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} !.mt-tb\.cgi*
RewriteCond %{HTTP_REFERER} !.*unix-girl\.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^-$
RewriteRule (.*) /post_error.html [R,L]
The above Rule will send anyone who tries to post to my server without a referer from my domain to an error page. Of course, many spam bots use the actual url they're posting to as a referer.. for those just need to depend on either the user agent (one I saw was just "-") or some idea I'll come up with later.
Side benefit: also stops all those stupid scripts looking for formmail and friends.
Edit: Added a line which will except trackbacks.