Connecting Tech Pros Worldwide Help | Site Map

Using .htaccess to variably block hotlinking

Member
 
Join Date: Aug 2007
Posts: 58
#1: Jul 1 '08
Hi folks,

I need to combine these two functions and I'm not sure how to go about it. I know how to use .htaccess to prevent anyone from hotlinking the images on my site.

What I basically want to do is to (1) prevent anyone, anywhere from hotlinking my images and (2) prevent anyone from MySpace from hotlinking to my site at all (whether images or otherwise).

Now I currently have my .htaccess like this:

Expand|Select|Wrap|Line Numbers
  1. RewriteEngine on
  2. RewriteCond %{HTTP_REFERER} !^$
  3. RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
  4. RewriteRule \.(gif|jpg)$ http://www.mydomain.com/theft.jpg [L]
  5.  
This prevents anyone from hotlinking gif or jpg files on my site, and instead displays the "theft.jpg" image. Works great. But how do I combine this to not allow MySpace to link to *anything* on my site, whether images or otherwise.

Thanks for any assistance you can provide.

Robert
Reply