Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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} ! [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

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
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


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.