Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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? –  Foo_Chow Sep 30 '13 at 23:57
add comment

1 Answer

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. –  Foo_Chow Oct 7 '13 at 20:58
add comment

Your Answer

 
discard

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.