rulururu

post Prevent Hotlinking from Specific Sites Only

July 2nd, 2008

Filed under: code, tools — bigw @ 11:29 am

You want to prvent hotlinking.

But not ALL websites. Sometimes you don’t mind if someone hotlinks from a forum or a review about your product, etc. However there are those that you DO want to block.

You can use the code below and place it into your htaccess file.

I placed the code in the .htaccess file inside my images folder, to just protect that folder, and to keep things straight forward.

If you wish to send a differnt image to the offending website, change the last line to an image that is outside your domain, or in a folder a level above where your .htaccess file is located.

Example: If I placed the code in the .htaccess file inside http://example.com/images, then my “nohotlink.jpg” image should be located http://example.com/nohotlink.jpg (otherwise it will blocked by it’s own rule).

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?ebay\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?ebay\.ca/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?abc\.net/ [NC]
RewriteRule .*\.(jpg|gif|bmp|png)$ http://example.com/nohotlink.jpg [L]

1 Comment »

  1. THANK YOU!

    I’ve been trying all sorts of code from various sites and they all ended up making my links on other sites come up horribly wrong. Looking like I hotlinked from my own site TO my own site was especially embarassing.

    This code worked. Thanks again.

    Comment by MontiLee — August 8, 2008 @ 2:45 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment

ruldrurd
Powered by WordPress Entries (RSS) and Comments (RSS)