|
HOW TO: Prevent referrer spam |
|
Written by Brian Austin
|
|
Wednesday, 01 November 2006 |
 I had to apply this trick to another one of my sites. Despite my instructions for Google to not cache the bugger, and various link following bots, I've started to get spamed in the anonymous comments section. Because of my audience I want to keep comments anon for now since it's easier to use and doesn't require registration. Anyway the following is a script that I've been using for a while that works with Apache.
It requires 3 files: .htaccess, redirect.html and forbidden.html. The last two are just regular HTML files that contain a message a valid link to the site. The first directs Apache to deny access to a set list of IP addresses or domains, and to only accept referrers (i.e. links from other sites) that are in the list. This file uses regular expressions so don't worry about the strange directives. Just remember to always \ escape your "."s. Enjoy!!
Save the following as .htaccess and upload to your site's root directory:
order allow,deny
deny from .agava.net
deny from .net.qa
deny from 202.56.
deny from .qualitynet.net
deny from .bbt.net.ar
deny from .my
deny from .intercage.com
deny from .net.il
deny from 217.160.
allow from all
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^[http|nttp].*$
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !electronicrealitysolutions\.com [NC]
RewriteCond %{HTTP_REFERER} !ultimateracinggame\.com [NC]
RewriteCond %{HTTP_REFERER} !google\.com [NC]
RewriteRule $ redirect.html [L]
SecFilterEngine On
ErrorDocument 403 /forbidden.html
|