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

  • These lines should go inside the VirtualHosts context.
    – sysadmin1138
    Sep 30, 2013 at 23:50
  • So it is not possible to add this directive to all domains through httpd.conf then? Sep 30, 2013 at 23:57

1 Answer 1


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
  • Makes sense, thanks for the information. Good to know it is possible at a global scope. Oct 7, 2013 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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