0

I have been searching for a way to block with .htaccess other domains from downloading images and as far as now this is the answer I like the most, with some modifications:

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com [NC]
#RewriteCond %{HTTP_REFERER} !^http://(www\.)?otherdomain\.com [NC]
RewriteRule \.(gif|jpe?g|js|css)$ - [F,NC,L]

Good one and works, but only for certain images.

Is there any way to block access to all images?

Thanks in advance.

UPDATED: All my image files are in mydomain.com/Images

Community
  • 1
  • 1
PDR
  • 71
  • 1
  • 11
  • I don't think there is a directive to include all image types. That's possible when they are in one or more directories, blocking access to the directories not to the files. Why don't you try adding the missing extensions to the code in your question? – Felipe Alameda A Dec 01 '12 at 05:34
  • Thanks for the answer. You are right I shouldn't be trying to block access to each file but to the directories where they are. I'll update the answer. – PDR Dec 01 '12 at 06:37

1 Answers1

1

In that case, you may want to try this:

RewriteCond expr "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'"
RewriteRule ^/images - [F, NC]     # No need for L, it is implied when using F
Felipe Alameda A
  • 11,791
  • 3
  • 29
  • 37