Using .htaccess to block referrer spam

To block these spam referrers you need the following lines in your .htaccess file:
# set the spam_ref variable

SetEnvIfNoCase Referer “^http://(www.)?some-spammer.com” spam_ref=1

SetEnvIfNoCase Referer “^http://(www.)?other-spammer.com” spam_ref=1

SetEnvIfNoCase Referer “^casino-poker” spam_ref=1

# block all referres that have spam_ref set
<FilesMatch “(.*)”>
Order Allow,Deny
Allow from all
Deny from env=spam_ref
</FilesMatch>

The first lines “setenvifnocase” assign a span_ref environment variable. Then we deny all access to such referrers in the FilesMatch clause.

You can also use wildcards with the above .htaccess directives to match a variety of hosts. For example, you can use

SetEnvIfNoCase Referer “*some_word*” spam_ref=1

to match all referrers that contain the word ’some_word’.

Posted by Mahesh ( Tryangled )

Leave a Reply

You must be logged in to post a comment.