Using Apache to Block Image Leeches

Pronet Advertising advises you to “Protect Your Site’s Content” and they give a plug to a $200 tool that helps those poor souls using IIS as their web server. If you’re running the open source apache web server, here’s a free solution I worked out after many MySpace users starting embedding funny photos from PlanetMike.com into their web pages:

  1. Create an image to send to people that attempt to leech your images. you could be rude or mean, but I simply put up an ad for my own web site. Keep it as small as you can, since it may be used a lot. My photo is at http://www.planetmike.com/images/no-hot/linking.jpg.
  2. Ideally, put this into a directory block in your httpd settings file. Or you can put it into your .htaccess file.
    RewriteEngine onRewriteCond %{REQUEST_FILENAME} !^/images/no-hot/linking\.jpg$RewriteCond %{HTTP_REFERER} !^$ [NC]RewriteCond %{HTTP_REFERER} !^http://(www\.)?planetmike.com/ [NC]RewriteRule \.(jpe?g)$ /images/no-hot/linking.jpg [L]RewriteEngine off

    Line 2 is the image you want people to see (your ad or nasty note).

    Line 3 allows normal images to be sent to people who don’t send a referrer.

    Change line 4 to be your domain name. This domain will be allowed.

    Line 5 changes what image is sent on image requests. If a jpg is requested send the replacement image.

  3. Restart your web server and test.

That’s all there is to it. Definitely let me know if you have problem with this.

If you're new here, you may want to subscribe to my RSS feed. This allows you to read my newer articles without having to visit the site again. Thanks for visiting! Mike

Posted under Web-design

This post was written by Michael Clark on May 15, 2007

Leave a Comment

Name (required)

Email (required)

Website

Comments

More Blog Post

Previous Post: Vistaprint sucks