Preventing Image Bandwidth Theft Using Apache

I recently noticed this site’s images were getting a lot of hits – only the images, not the pages they were posted to. I discovered a lot of users of forums and chats linking directly to the images on this site, instead of copying the image and hosting it on their own website. This type of image linking is a drain on my poor server, and it’s considered bandwidth theft.

Here’s the code in my Apache httpd.conf file to prevent websites from “stealing” my images:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?steelwhitetable\.org [NC]
RewriteCond %{HTTP_REFERER} !^http://(www.)?cairns.servehttp\.com [NC]
RewriteCond %{HTTP_REFERER} !^http://(www.)?bloglines\.com [NC]
RewriteRule .(gif|jpg|png)$ - [F]

This prevents .gif, .jpg., and .png files from being displayed on any website except those specified. So, if I wanted to allow to display my images, I would add the following to the above:

RewriteCond %{HTTP_REFERER} !^http://(www.)?google/.*$ [NC]

You could even redirect those attempting to use a direct link to an image on your website to a different image. Add the following before the RewriteRule, where “bad.jpg” is the image that will be displayed on other websites:

RewriteCond %{REQUEST_URI} !^/bad.jpg$ [NC]

7 Replies to “Preventing Image Bandwidth Theft Using Apache”

  1. You should set the “bad.jpg” to be one of those pictures of naked 800 pound ladies showing off their sexy hot whale-bodies with small birds eating the parasites from the many many small crevices.

  2. somethingawful wasn’t the culprit. It was mainly from subject-specific sites where people used images from my site as avatars, or some forums simply posted the images after doing a google search.

  3. Do you know how to do that in IIS? Not that anyone goes to my site to get anything. But that is not the point, is it?

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.