Andrew Trembley (bovil) wrote,
Andrew Trembley

  • Mood:
  • Music:


I don't look at my web page statistics very often. I get enough monthly hits that I don't have to feel neurotic about it.


I found quite a few instances where folks were leeching images (the "Stewie" portrait thumbnail is very popular) for web forum user icons and .sig lines. Now I'm not going to search for folks who have swiped a copy and host it on their own servers (it's not like i've got permission to use the image in the first place), but I've got no interest in offering up my bandwidth to someone who is going to use the image for something other than linking to my site.

Fortunately for selfish bastards like me, there's this thing called mod_rewrite and a lot of nice tutorials and hints on how to make it work for you.

This is the ruleset I like...
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?bovil\.com [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?irlm\.org [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?twistedimage\.com [NC]
RewriteCond %{HTTP_REFERER} !^http://(.+)?livejournal\.com [NC]
RewriteCond %{HTTP_REFERER} !.*search\?q\=cache.* [NC]
RewriteCond %{HTTP_REFERER} !.*search/cache\?.* [NC]
RewriteRule .*\.(gif|jpg)$ - [F,L]

What does this do? It's designed to exit if any condition is matched, and fail the image load if none do.
  • The first condition bails when there is no referrer. This is important, some browsers and firewalls supress referrer information, and you don't want to block them.

  • The following three bail when the referring URL matches preferred domains that I'm willing to let link images in. It's important to remember to include your site as one that's allowed to link images.

  • The "livejournal" condition bails on any LJ url. I host images for my journal on my webserver

  • The "cache" conditions bail when an image-search cache page loads the image.

  • The last line (rule) returns a failure code for gif and jpg images if no condition has been matched.

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded