Saving some valuable bandwidth

Monday Aug 29 2005

I've just started to block single words for referring sites in my .htaccess. Referrer are stealing so much bandwidth that it's not even funny anymore. can generate .htaccess rules but usually they're one rule per domain and some regexps that still don't catch enough to my taste. The most agressive thing one can do is blocking single words. Sure it will probably result in some false positives but I guess everything is better than having to pay your ass off due to massive amounts of stolen bandwidth due to . Here's how...

updated!

Dark Matter Pro: a premium photoblog template.

Affiliate program available

So if you want to block single words too, put the following in your .htaccess file:


# Single word blocks
RewriteEngine On
RewriteCond %{HTTP_REFERER} poker [OR]
RewriteCond %{HTTP_REFERER} medicine [NC,OR]
RewriteCond %{HTTP_REFERER} pills [NC,OR]
RewriteCond %{HTTP_REFERER} diet [NC,OR]
RewriteCond %{HTTP_REFERER} viagra [NC,OR]
RewriteCond %{HTTP_REFERER} mortgage [NC,OR]
RewriteCond %{HTTP_REFERER} casino [NC,OR]
RewriteCond %{HTTP_REFERER} insurance [NC,OR]
RewriteCond %{HTTP_REFERER} loan [NC,OR]
RewriteCond %{HTTP_REFERER} buy [NC,OR]
RewriteCond %{HTTP_REFERER} xanax [NC,OR]
RewriteCond %{HTTP_REFERER} meridia [NC,OR]
RewriteCond %{HTTP_REFERER} incest [NC,OR]
RewriteCond %{HTTP_REFERER} lesbian [NC,OR]
RewriteCond %{HTTP_REFERER} viagra [NC,OR]
RewriteCond %{HTTP_REFERER} adult [NC,OR]
RewriteCond %{HTTP_REFERER} hentai [NC,OR]
RewriteCond %{HTTP_REFERER} tramadol [NC,OR]
RewriteCond %{HTTP_REFERER} phentermine [NC,OR]
RewriteCond %{HTTP_REFERER} gambling [NC,OR]
RewriteCond %{HTTP_REFERER} texas- [NC,OR]
RewriteCond %{HTTP_REFERER} holdem [NC,OR]
RewriteCond %{HTTP_REFERER} pharmacy [NC,OR]
RewriteCond %{HTTP_REFERER} ultram [NC,OR]
RewriteCond %{HTTP_REFERER} tramadol [NC]
RewriteRule .* - [F,L]


You can add as many words as you want, as long as the first rule has only [OR] and the last rule only [NC]. Otherwise it won't work. An easy way to do it is to copy/paste my example and just add lines in the middle like:


RewriteCond %{HTTP_REFERER} your_word_to_block [NC,OR]


If the referrer contains the word, it will be blocked. This strategy will block many sites, for example the viagra one will block stuff like: www.buy-viagra.com but also stealth domains like www.7zulu.com/viagra.html etc. etc.

I also added an extra rule in order to be not all that harsh:


ErrorDocument 403 /honeypot/403.php


This means that whoever is caught by the rules will get this page which is slightly friendlier than a standard 403 / Forbidden notice while still not taking up too much kilobytes.

To further annoy the spammer I've put the following php code in my 403 document:


<?php
echo "If you see this, your referrer:".$_SERVER["HTTP_REFERRER"]." has been marked as a spam referrer. Click <a href=\"".$_SERVER["R
EQUEST_URI"]."\">HERE</a> to access the page anyway.<br /><br />";
flush();
for($i=0;$i<10;$i++) {
echo "p";
sleep(5);
flush();
echo "i";
sleep(5);
flush();
echo "s";
sleep(5);
flush();
echo "s";
sleep(5);
flush();
echo " ";
sleep(5);
flush();
echo "o";
sleep(5);
flush();
echo "f";
sleep(5);
flush();
echo "f";
sleep(5);
echo " ";
flush();
echo "s";
sleep(5);
flush();
echo "p";
sleep(5);
flush();
echo "a";
sleep(5);
flush();
echo "m";
sleep(5);
flush();
echo "m";
sleep(5);
flush();
echo "e";
sleep(5);
flush();
echo "r";
sleep(5);
flush();
echo "s";
sleep(5);
flush();
echo "<br />";
}
?>


This will make the request be sloooooooooooooow as hell... (try it here)
bookmarking

Commentary

Join the discussion! Leave a comment through the comment form below!

Got something to add to this?

Feel free to leave a comment on this site. You can use Textile and Emoticons. Your email address is only used to show a gravatar. Please stay on-topic and use common decency. Spammers will be shot in front of a live studio audience.

If you plan on posting code, use pastebin please and post a URL to the code. The comment processing doesn't deal very well with code. Sorry for the inconvenience.

Human comment spammers: don't bother posting your crap here. Comments are moderated and I won't let any of your shit through.

Remember personal info?
Yes
No

Trackbacks

If you have an interesting related post on your own site you can leave a trackback. As they say: 'a little AJAX a day keeps the spammers away' which is why you'll have to click below to generate a trackback key. The key will be valid for 15 minutes and can be used only once.

Spam
Lately I am getting lots of spam comments to my blog entries, mainly concerned with pornographic sites or anti-impotence drugs sale. This is really annoying, and although my comments are not published automatically, but are rather stored in approval queuSent on 12 September '06 - 02:55 , via andre bar'yudin

 

  • Featured Links
RockySomewhere near the Orion NebulaBookalicio.usGolden Gate BridgeThames River BankJackie and mePimpin' it