Forum Moderators: phranque

Message Too Old, No Replies

Image Hotlink Protection with Htaccess Issue

Hotlink protection not working for htaccess

         

ranadeep

9:38 pm on Apr 8, 2009 (gmt 0)

10+ Year Member



I had this issue recently. A very common one I guess but I could not come across with a solution.

I have recently used htaccess to protect hotlinking of images from my site as bandwidth overage was cutting deep into my pocket. I have used a small gif file to replace the hotlinked image. After a few tweaks here and there it did work, but when I try to look at the images at my own site that have been hotlinked, the replacement image is being shown until I refresh the page. Once I refresh the page it goes and the original image is shown again.

I don't know why this is happening and the only option left for me is to stop the hotlinking protection which means I have to pay a huge load on bandwidth overage and eventually close down my site.

Can someone please help? Also, in case it is already there on the forum and I missed, please direct me to the thread.

jdMorgan

10:10 pm on Apr 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Flush your browser cache before testing -- You are simply seeing the cached "no hotlinking" image saved by your browser, and no request is being sent to your server for a 'new' copy of the image.

This is just an annoyance to you, it does not mean that your anti-hotlinking code isn't working.

Your best bet if you want to avoid this issue completely is to forget about serving an alternate image, and simply respond with a 403-Forbidden response, taking care that your custom 403 error page (if any) is very small and is marked as non-cacheable.

I make my custom 403 error page very small by leaving out all unnecessary headers, styling and formatting, and providing only the simple message "Access Denied - click here [WebmasterWorld.com] for more info." The link goes to a 'friendlier' page which explains the error and provides links to the home page and other 'help' pages.

Jim