May 11 2005

Preventing Image Bandwidth Theft Using Apache

Jody posted this at 7:55 pm under internet & computers

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 google.com 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 Responses to “Preventing Image Bandwidth Theft Using Apache”. Leave a Reply.

  1. Penderon 11 May 2005 at 10:45 pm

    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. ChrisOon 12 May 2005 at 5:44 pm

    haha, i hate somethingawful!

  3. Jodyon 12 May 2005 at 8:05 pm

    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.

  4. Gregon 15 May 2005 at 9:08 pm

    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?

  5. Jodyon 15 May 2005 at 9:35 pm

    I have no idea how to do it using IIS. That’s one of the reasons why I switched to Apache.

  6. Lennarton 22 May 2005 at 6:45 am

    Is that why there is only broken images when read thru bloglines?

  7. Jodyon 24 May 2005 at 5:08 pm

    The images show up in my bloglines subscription to the feed. The feed is http://steelwhitetable.org/blog/feed just in case.

Comments RSS

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Note: This post is over 3 years old. You may want to check later in this blog to see if there is new information relevant to your comment.

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution.