Mikedowney.co.uk
What's New
Site Map

Diary
Astronomy
Bits N Bobs
Computing
Food And Drink
Links
Photography
Welcome


Selected Entries
Pinhole Photography
Keeping Quail
Coventry
Recipes
Friends websites
A list of pet related websites
Celebrity Stiffs League

Most popular clicks
Coventry
Hamsters
Pinhole
Shopping
Food And Drink
Bits N Bobs
Astronomy
Humour
Birmingham
Animals


RSS Feeds:
RSS Feed Entire Site.
RSS Feed Diary only.


Advanced Search


Powered by Blosxom


Pinhole Photography Ring
pinhole webring logo
powered by RingSurf
Next | Previous
Random Site | List Sites

Trying to prevent image theft 1: Using .htaccess

Story location: Home / computing /
13/Apr/2008

I've had a problem recently with people stealing images from my website - either hot-linking them or re-uploading them to other sites. My first attempt to stop this was by modifying the .htaccess file on the web server, telling it to only allow image requests from recognised places.

This works because most browsers send a 'referrer' value which tells the web server where the request came from. If I display an image on my site, the referrer should be 'mikedowney.co.uk', which would be allowed. Requests from other sites would be disallowed.

This should work with most sites hosted on an Apache server. I added the following lines to the .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mikedowney.co.uk [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.(\.)? [NC]
RewriteRule \.(jpg|jpeg|gif)$ /image_error.png [NC,R,L]

The first line tells the server we are using the RewriteEngine to change how some URLs are handled. The next 3 lines specify which referrers are allowed to link to images. We have:

  1. Empty referrer. This is because some browsers may not correctly fill in the 'referrer' line when requesting images.
  2. This website - it would be pointless to disallow me from showing my own images.
  3. Any of the google servers - so that the google image search will work properly. The (.)? bit at the end should match different countries, such as google.com or .co.uk etc.

The final line gives the file types this applies to and the file to display if it matches. In this case, an image with an error message.


0 comments, click here to add the first permanent link
Keywords:  

Leave a comment...

 
Name:
URL/Email: [http://... or mailto:you@wherever] (optional)
Subject: (optional)
Comments:
How many animals?

Type in how many animals you see.
This is required to verify
that you are an actual human
to reduce 'comment spam'.
Type in how many animals appear in the image. Sorry, this does not work without the image being visible  



Streamline.Net The home of good value web hosting