0

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.

oshirowanen
  • 292
  • 3
  • 13

1 Answers1

2

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

See Hot linking images

PP.
  • 3,246
  • 6
  • 26
  • 31
  • 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 ``...`` tags, or an `.htaccess` file. – PP. Oct 18 '10 at 15:06