Archive for July, 2011

.htaccess file to block some spammers

Thursday, July 28th, 2011

I find referer spam annoying. Referer spam is spam that appears in my log as bogus http_referer entries – referer is misspelled for historic reasons. I also think that spammers who drop by also leave their dirt behind in the logs. By blocking certain strings in the referrer string, I think I can stop a few spammers also.

I’ve been testing the following referer string block. I have no idea if it is working, yet. I am going to set a bogus page with one of the strings in it to test it out.

Make a backup copy of your .htaccess file and then copy this stuff into the top of the file.

Test it. I got 500 errors when I made a mistake, so be sure you have a backup copy that works in order to restore the file if it breaks your site.

Make sure you leave the wordpress stuff and anything else needed to run your site after this code.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# referrer spam
RewriteCond %{HTTP_REFERER} poker [NC,OR]
RewriteCond %{HTTP_REFERER} viagra [NC,OR]
RewriteCond %{HTTP_REFERER} casino [NC,OR]
RewriteCond %{HTTP_REFERER} sex [NC,OR]
RewriteCond %{HTTP_REFERER} qzone [NC,OR]
RewriteCond %{HTTP_REFERER} jokes [NC,OR]
RewriteCond %{HTTP_REFERER} calories [NC,OR]
RewriteCond %{HTTP_REFERER} alliatemarketing [NC,OR]
RewriteCond %{HTTP_REFERER} mafia [NC,OR]
RewriteCond %{HTTP_REFERER} erotic [NC,OR]
RewriteCond %{HTTP:VIA} ^.+pinappleproxy [NC,OR]
RewriteCond %{HTTP_REFERER} nestseekers [NC,OR]
RewriteCond %{HTTP_REFERER} porn [NC,OR]
RewriteCond %{HTTP_REFERER} advair [NC,OR]
RewriteCond %{HTTP_REFERER} allegra [NC,OR]
RewriteCond %{HTTP_REFERER} ambien [NC,OR]
RewriteCond %{HTTP_REFERER} amoxicillin [NC,OR]
RewriteCond %{HTTP_REFERER} baccarat [NC,OR]
RewriteCond %{HTTP_REFERER} blackjack [NC,OR]
RewriteCond %{HTTP_REFERER} cash [NC,OR]
RewriteCond %{HTTP_REFERER} casino [NC,OR]
RewriteCond %{HTTP_REFERER} celeb [NC,OR]
RewriteCond %{HTTP_REFERER} cheap [NC,OR]
RewriteCond %{HTTP_REFERER} cialis [NC,OR]
RewriteCond %{HTTP_REFERER} craps [NC,OR]
RewriteCond %{HTTP_REFERER} credit [NC,OR]
RewriteCond %{HTTP_REFERER} deal [NC,OR]
RewriteCond %{HTTP_REFERER} debt [NC,OR]
RewriteCond %{HTTP_REFERER} drug [NC,OR]
RewriteCond %{HTTP_REFERER} effexor [NC,OR]
RewriteCond %{HTTP_REFERER} equity [NC,OR]
RewriteCond %{HTTP_REFERER} faxo [NC,OR]
RewriteCond %{HTTP_REFERER} finance [NC,OR]
RewriteCond %{HTTP_REFERER} gambling [NC,OR]
RewriteCond %{HTTP_REFERER} hold-em [NC,OR]
RewriteCond %{HTTP_REFERER} holdem [NC,OR]
RewriteCond %{HTTP_REFERER} iconsurf [NC,OR]
RewriteCond %{HTTP_REFERER} insurance [NC,OR]
RewriteCond %{HTTP_REFERER} interest [NC,OR]
RewriteCond %{HTTP_REFERER} internetsupervision [NC,OR]
RewriteCond %{HTTP_REFERER} keno [NC,OR]
RewriteCond %{HTTP_REFERER} levitra [NC,OR]
RewriteCond %{HTTP_REFERER} lipitor [NC,OR]
RewriteCond %{HTTP_REFERER} loan [NC,OR]
RewriteCond %{HTTP_REFERER} meds [NC,OR]
RewriteCond %{HTTP_REFERER} money [NC,OR]
RewriteCond %{HTTP_REFERER} mortgage [NC,OR]
RewriteCond %{HTTP_REFERER} omaha [NC,OR]
RewriteCond %{HTTP_REFERER} paxil [NC,OR]
RewriteCond %{HTTP_REFERER} pharmacy [NC,OR]
RewriteCond %{HTTP_REFERER} pharmacies [NC,OR]
RewriteCond %{HTTP_REFERER} phentermine [NC,OR]
RewriteCond %{HTTP_REFERER} pheromone [NC,OR]
RewriteCond %{HTTP_REFERER} pills [NC,OR]
RewriteCond %{HTTP_REFERER} poker [NC,OR]
RewriteCond %{HTTP_REFERER} refinance [NC,OR]
RewriteCond %{HTTP_REFERER} roulette [NC,OR]
RewriteCond %{HTTP_REFERER} seventwentyfour [NC,OR]
RewriteCond %{HTTP_REFERER} slot [NC,OR]
RewriteCond %{HTTP_REFERER} syntryx [NC,OR]
RewriteCond %{HTTP_REFERER} texas [NC,OR]
RewriteCond %{HTTP_REFERER} tournament [NC,OR]
RewriteCond %{HTTP_REFERER} tramadol [NC,OR]
RewriteCond %{HTTP_REFERER} tramidol [NC,OR]
RewriteCond %{HTTP_REFERER} valtrex [NC,OR]
RewriteCond %{HTTP_REFERER} viagra [NC,OR]
RewriteCond %{HTTP_REFERER} vicodin [NC,OR]
RewriteCond %{HTTP_REFERER} xanax [NC,OR]
RewriteCond %{HTTP_REFERER} zanax [NC,OR]
RewriteCond %{HTTP_REFERER} zoloft [NC]
RewriteRule .* - [F]
</IfModule>