Forum Moderators: phranque

Message Too Old, No Replies

Hotlinking - allow 2 domains but disallow others?

Sorry if this has been discussed before

         

bondjamesbond

10:52 am on Nov 13, 2003 (gmt 0)

10+ Year Member



Hi, I've done a search here to try to find a solution to my problem but I couldn't find anything specfic. Please excuse me if this has been discussed before, as I must be blind!

I have been reading lots of topics about preventing hotlinking, it looks a very useful tool. I know you can use various ways, like displaying images, redirecting etc. What I am hopefully looking to do is only allow images to be shown if the referrer comes from 1 or 2 domains. The majority of my images are held on another server with a few held with my files. How can I only allow images from my server with all the files, or images from the main image server and present any other hotlinkers with a forbiden message?

I appreciate anyone who can help! =)

bondjamesbond

2:31 pm on Nov 13, 2003 (gmt 0)

10+ Year Member



Hi,

I have found this code,

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^http://(www\.)?firstdomain\.com [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?secondomain\.com [NC]
RewriteRule \.(gif¦jpg)$ - [F]

would this do the job? Would it only allow images to be displayed if the referer was firstdomain.com or seconddomain.com?

Thanks

bondjamesbond

7:48 pm on Nov 13, 2003 (gmt 0)

10+ Year Member



Ok,

I have been giving this some more thought. Here is the code I am currently using :-

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mydomain\.co.\uk [NC]
RewriteRule \.(gif¦jpg)$ - [F]

After doing some research, how I understand the above works is that if the request to get an image from mydomain.co.uk is not mydomain.co.uk then deny access. So when my site tries to access an image it allows it but when anyone else tries to access an image they cant.

However it doesn't seem to work. As I have said above I use two servers. Server A contains only my images and no files, Server B (mydomain.co.uk in this example) contains all my files and a very small number of images. I have created a test file and placed it on Server A linking to an image on Server B. In theory it shouldn't display it as its referer is not mydomain.co.uk - so why does it not work?

Is it a problem with the code or could my host not support mod_rewrite?