PDA

View Full Version : Using .htaccess to stop image leeching


PKIDelirium
2006-06-09, 20:34
OK... I want to stop hotlinking of images, but I only want to do it from referrers that I specify (in this case, my competition).

A programmer friend gave me code for it earlier, but it didn't work.


RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?badsite\.com/ [NC]
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/hotlink.jpg [L]


Any ideas? It blocked the leeched images properly by breaking them, but the replacement image (hotlink.jpg) did not display.

Brad
2006-06-09, 20:38
Try changing that last line to:


RewriteRule \.(jpe?g|gif|bmp|png)$ /images/hotlink.jpg [L]

PKIDelirium
2006-06-09, 20:52
Bingo! Worked great, thanks.

PKIDelirium
2006-06-11, 12:42
I'm having a problem again.

I tried to set t for multiple referrers and it does not properly display the hotlink.jpg now, it's back to just breaking the image,


RewriteEngine on
RewriteCond %{HTTP_REFERER} forums.applenova\.com [NC,OR]
RewriteCond %{HTTP_REFERER} klockster\.com
RewriteRule \.(jpe?g|gif|bmp|png)$ /images/hotlink.jpg [L]


I have those URLs in it for testing purposes, as you can see below:

http://www.extremepki.com/images/greatwolf/thm_image1.jpg

Breaks the image, but doesn't display the hotlink.jpg

Edit: Having the alternate image as a .jpg was tossing it into a server loop, so I replaced the code with one that will just break the images. Problem fixed for now.