Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Possible Duplicate:
How is anti-hotlinking done?

I have a lot of images on my site and I don`t want to let other people to use my images on their sites. Is there any way to block the use of my images from other sites, maybe with .htaccess?

share|improve this question

migrated from stackoverflow.com Nov 21 '11 at 20:10

This question came from our site for professional and enthusiast programmers.

marked as duplicate by John Conde Nov 21 '11 at 20:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

RewriteEngine On
RewriteCond %{HTTP_REFERER}  !^$
RewriteCond %{HTTP_REFERER}  !^https?://www\.domain\.com$ [NC]
RewriteCond %{HTTP_REFERER}  !^https?://subdomain\.domain\.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://google.com/thief.png [R,NC,L]

to allow people view images:

RewriteEngine On
RewriteCond %{HTTP_REFERER}  ^$ [OR]
RewriteCond %{HTTP_REFERER}  !^https?://www\.domain\.com$ [NC]
RewriteCond %{HTTP_REFERER}  !^https?://subdomain\.domain\.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://google.com/thief.png [R,NC,L]
share|improve this answer
    
Note: if you want to enable users to view image by typing URL in address bar, remove Second line! –  undone Nov 21 '11 at 16:49
    
Only removing the second line wont allow people to view the image by typing the url directly into the address bar –  Tom Knapen Nov 21 '11 at 17:07
    
@Tom you're right, I'll change the code –  undone Nov 21 '11 at 17:35