Preventing Image theft with Apache's .htaccess Tags:, ,

Do you have an image or images that people are using on their site, Not giving you the credit for your artwork and using your bandwidth?

With a simple .htaccess on your Apache server you can prevent Image HotLinking.

In your Images Directory, or in your mail web root if you have multiple image areas create a .htaccess file. If you already have one, we can just append the following code in to that.

Insert this in to your file.

RewriteEngine On
# REPLACE lendrum\.co.nz WITH YOUR DOMAIN NAME
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?lendrum\.co\.nz/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ - [F]

This will send a 403- Forbidden message to all external sites calling your images.

You can allow multiple domains to access the images if you have more pointing to your site, or want certain sites to use your images.

RewriteCond %{HTTP_REFERER} !^http://(.+\.)?lendrum\.co\.nz/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?inboxdesign\.co\.nz/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?apple\.co\.nz/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?apple\.com/ [NC]

If you want to send a different image, rather than a 403 error you can change the last line to this: But this is almost defeating the purpose, but it will let the visitors on the other sites know that the webmaster is an image thief

RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/DoNotSteelMyImages.jpg [L]

Simple :)

Note: This will only work on Apache Servers.

Related posts:

  1. PHP Captcha Image Verification
  2. Installing PHP5 and mySQL on Mac OSX Leopard
  3. Administration plugin for Minishowcase Gallery system
  4. Virtual Web Hosting on OSX Leopard
  5. Changing the RSS refresh rate in Apple Mail

One Response to “Preventing Image theft with Apache's .htaccess”

  1. Cenk 12/08/2008 04:26pm

    Great!

    Thanks Sheldon.

Subscribe Via Email Notify me of followup comments via e-mail