Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 am trying to prevent hot linking of images on our site. I have tried editing

/etc/httpd/conf/httpd.conf by adding the following to the end of the file:

<VirtualHost *:80>
DocumentRoot /var/www/html/
ServerPath /
SetEnvIfNoCase Referer "myserver’" local_ref=1
<FilesMatch "’.(gif|jpg|jpeg|png)">
Order Allow,Deny
Allow from env=local_ref

But this does not seem to prevent hot linking. I know I can also prevent hot-linking from within the .htaccess file, but wanted to know why my attempt to do it via the httpd.conf file is failing?

I have also tried:

SetEnvIfNoCase Referer "^http://www\.myserver\.co\.uk/" banimages=1
SetEnvIfNoCase Referer "^http://myserver\.co\.uk/" banimages=1
SetEnvIfNoCase Referer "^$" banimages=1
<FilesMatch "\.(gif|png|jpe?g)$">
  Order Allow,Deny
  Allow from env=banimages=1

Which did not work either. What I am doing wrong?

EDIT: I have not also tried the following 4 lines at the end of the httpd.conf file as is, without placing them in any tag like the virtualhost tag:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !=""
RewriteCond %{HTTP_REFERER} !mysite\.co\.uk [NC]
RewriteRule \.(jpe?g|gif|png)$ - [F,NC]

The images still seem hotlinkable.

share|improve this question
up vote 2 down vote accepted



share|improve this answer
Do I just stick those 4 lines into the httpd.conf file at the end, or do they need to go between specific tags like the virtualhost tag in the httpd.conf file? I am asking because, simply copying and pasting those lines and changing the to my url does not work. It does not stop hot linking. – oshirowanen Oct 18 '10 at 14:58
Best to put rewrite rules into a set of <Directory ...>...</Directory> tags, or an .htaccess file. – PP. Oct 18 '10 at 15:06

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.