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>
ServerName www.myserver.co.uk
ServerAlias myserver.co.uk
DocumentRoot /var/www/html/www.myserver.co.uk
ServerPath /www.myserver.co.uk
SetEnvIfNoCase Referer "myserver’.co.uk" local_ref=1
<FilesMatch "’.(gif|jpg|jpeg|png)">
Order Allow,Deny
Allow from env=local_ref
</FilesMatch>

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

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.

link|improve this question

feedback

1 Answer

up vote 2 down vote accepted

See http://wiki.apache.org/httpd/RewriteImageTheft

See http://serverfault.com/questions/191999/hot-linking-images

link|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 example.com 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
feedback

Your Answer

 
or
required, but never shown

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