Take That, Bandwidth Leeches

A recent trip through my hit reports revealed a startling fact: This site’s bandwidth is being heavily leeched.

Yes, I never thought it could happen to me, an innocent little development blog that posts an occasional hot babe. But then, it did happen; it seems many, many people like the image of the fat Denver Broncos cheerleader candidate, and have been hotlinking to it from many, many BBS.

So, I have struck my revenge with mod_rewrite. With a couple lines of code, you can pretty much shut down hotlinking of images and other resources, period:

RewriteEngine On
RewriteCond *{HTTP_REFERER} !^http://(www\.)?dougv\.com/ [NC]
RewriteCond *{HTTP_REFERER} !^$
RewriteRule \.(jpe?g|gif|png|zip)$ http://www.freewebs.com/dhvrm/noleech.jpg

Here’s a breakdown of the lines:

  1. Turn mod_rewrite on for this directory and all subdirectories. Subdirectories inherit mod_rewrite rules from their parent directories; parent directories ignore the mod_rewrite rules of their children.
  2. This condition is going to specifically exempt this domain (dougv.com) from the rule. If I didn’t specifically exempt this domain, this Web site wouldn’t show its own images.
    • The statement *{HTTP_REFERER} tells mod_rewrite, “check the browser’s request header, and get the URL of the page that referred the user here.”
    • The request header is a bunch of hidden data that is sent by a Web browser every time it asks for a file from a Web server.
    • Among the header data are what are called “environment variables”, or information about the Web browser being used. And among those “environment variables” is HTTP_REFERER, which is the link someone clicked in order to get to your page.
    • For example, suppose the page at http://www.somesite.com/index.php has a link to this blog entry, and someone clicked on that link. That person’s Web browser would indicate that http://www.somesite.com/index.php is the HTTP_REFERER.
    • If you simply open up your Web browser window and type a link by hand, or pull down a bookmark / favorite you previously saved, then HTTP_REFERER is an empty string.
    • mod_rewrite uses regular expressions to evaluate the HTTP_REFERER string. In our case, the regular expression !^http://(www\.)?dougv\.com/ means, “if the HTTP_REFERER does not [!] begin [^] with www.dougv.com OR dougv.com. (www\.)? means “www is optional.”
    • [NC] tells mod_rewrite to evaluate the expression as case-insensitive; so that http://www.dougv.com is the same as HTTP://WWW.DOUGV.COM
  3. This condition specifically requires the HTTP_REFERER to contain something, by saying, “if the HTTP_REFERER is not empty.”
  4. This does the magic. In our case, we’re substituting an offensive image if the bandwidth leech tried to steal a file that ends with the extensions jpeg, jpg, gif, png or zip. Again, we evaluate this as case-insensitive; the L switch tells mod_rewrite that this is the last rewrite rule. If we were to have more rewrite rules after this one, this would terminate all other rewriting instructions.

And now, if you have a strong stomach, you can see the surprise I have in store for all those bandwidth leeches by clicking the link below. Be forewarned: I intentionally wanted this image to be offensive.

This is what you get for stealing my bandwidth.

And if you’d like to see how this works out for just some of the lowlife bandwidth thieves who ripped me off, check out these links (and expect these links to be edited soon to remove the offending content):

http://forum.machinaesupremacy.com/index.php/topic,5362.45.html

http://www.dontstayin.com/chat/f-1/c-281/k-384615

http://www.freerepublic.com/focus/f-news/1890588/posts

Share This:
  • Digg
  • del.icio.us
  • StumbleUpon
  • Technorati
  • Slashdot
  • Facebook
  • DZone
  • DotNetKicks
  • Mixx
  • MisterWong
  • LinkedIn
  • Google Bookmarks
  • Yahoo! MyWeb
  • Windows Live Favorites
  • Print this

Leave a Reply