Forum Moderators: phranque

Message Too Old, No Replies

htaccess code to prevent photo theft

Recommendations on scripting problem

         

jonescd

7:06 pm on Jan 11, 2007 (gmt 0)

10+ Year Member



RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com/.*$ [NC]
RewriteRule \.(gif¦jpg)$ - [F]
RewriteRule \.(gif¦jpg)$ http://www.example.com/images/stealing.gif [R,L]

Has anyone used this above code in htaccess to block theft of your photos.
I used this particular code but it has caused all of my site's photos to not be visible when you upload the site.

Can someone please tell me what is wrong with this code?
Thanks,
Chris

[edited by: jdMorgan at 7:13 pm (utc) on Jan. 11, 2007]
[edit reason] Example.com [/edit]

jdMorgan

7:12 pm on Jan 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Choose one of the RewriteRules, not both.

Also, you will need to add an additional RewriteCond to the second rule, if you use it:


RewriteCond %{REQUEST_URI} !^/images/stealing\.gif$

Otherwise, requests for stealing.gif would redirect to stealing.gif, putting your server into a loop.

For general information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

jonescd

9:49 pm on Jan 11, 2007 (gmt 0)

10+ Year Member



Jim,

I have tried every combination of that code (including the removal and additions that you suggest) and I am still able to right click and save any photo.

I am on a Godaddy Apache Linux Shared hosting if that makes a difference.

Thanks,

Chris

willybfriendly

10:39 pm on Jan 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code you are using is meant to prevent "hot linking", i.e. to keep people from linking directly to you site to display the images on their site(s).

There is no way to prevent them from copying an image displayed in their browser, since it is by definition already downloaded from your server to their computer in order to be displayed.

You can use JS do disable the right click, but it is ineffective and will only anger some portion of your visitors.

If the images have enough value to protect, then watermarking would probably be the best option.

WBF

maccas

10:42 pm on Jan 11, 2007 (gmt 0)

10+ Year Member



"I am still able to right click and save any photo", that is to stop people hotlinking to your image on there website. There really isn't much you can do to stop people downloading your image, javascript no right click, hiding the image as a table background and watermarking your image is the best you can do, but there is always print screen for the dedicated.