Take the 2-minute tour ×

I have been trying to prevent hotlinking of images on a domain of mine without any success. I have added the following to /etc/apache2/httpd.conf

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !www.example.com [NC]
RewriteRule \.(jpg|jpeg|png|gif) - [F,NC,L]

This is the most basic example I have tried (this one is straight from the Apache site http://httpd.apache.org/docs/current/rewrite/access.html)

I have also tried adding a caret in front of the URL, adding slashes before the URL dots to escape them, making the www portion optional, adding https? in front of the URL, and not using the blank referrer line. All without success.

Should I be placing the rules elsewhere (such as a VirtualHosts file)?

share|improve this question
These lines should go inside the VirtualHosts context. –  sysadmin1138 Sep 30 '13 at 23:50
So it is not possible to add this directive to all domains through httpd.conf then? –  foochow Sep 30 '13 at 23:57

1 Answer 1

up vote 0 down vote accepted

Virtualhosts do not automatically inherit rewriterules that are defined in the main server context. If you want to inherit the rules you need to add this to each virtualhost context that you want to use the rules defined in the server context:

RewriteOptions Inherit
share|improve this answer
Makes sense, thanks for the information. Good to know it is possible at a global scope. –  foochow Oct 7 '13 at 20:58

Your Answer


