How to Prevent Others Linking (Hotlinking) to Your Website Images

| No Comments | No TrackBacks
Several years ago, I was checking through my website's web logs and discovered that another developer (I use the term loosely here) had decided to hotlink to one of my images, and they set my image as the background of their MySpace website. In fact, it was a MySpace website for their band.

I was not happy, so I swapped out the image for another one, which promptly tiled across their MySpace website. This was a highly amusing result, and within a week, they had taken the website down and relaunched it a couple of days later with a new background image. (At least they did not steal my image, but the fact that they were using it without permission and putting their web traffic through my website with requests to my image, was annoying.)

Instead of humiliating others, I wish that I had known that I could have prevented the developer from linking to my image through making changes to the .htaccess file.

This can be easily achieved by putting a few lines into the .htaccess file. First of all, however, you will need to create an image that the users will be redirected to if they do link to an image. This image can include some text that asks users not to link to your image.

After you have created the image, simply write your redirect rule to the image you created above. You will need to check the HTTP_REFERER of the request, and ensure that your website can link to the images. Afterwards, add your RewriteRule so that all other websites not mentioned in the RewriteCond will obtain the created image. An example is below (1).

RewriteEngine On

#Replace ?mysite\.com/ with your blog url

RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]

RewriteCond %{HTTP_REFERER} !^$

#Replace /images/nohotlink.jpg with your "don't hotlink" image url

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


The example above will prevent any websites besides your own from hotlinking to images, but you may want some websites to see your images. To allow Google or other search engine sites to continue linking to your image (so that it comes up in results), simply add the following lines:

RewriteCond %{HTTP_REFERER} !google\. [NC]

RewriteCond %{HTTP_REFERER} !msn\. [NC]

RewriteCond %{HTTP_REFERER} !yahoo\. [NC]

RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]


The above code can be adapted to meet your own demands and goals. 



1) How to protect your wordpress blog from hotlinking. http://www.wprecipes.com/how-to-protect-your-wordpress-blog-from-hotlinking

No TrackBacks

TrackBack URL: http://jenikya.com/cgi-bin/mt5/mt-tb.cgi/518

Leave a comment

Archives

OpenID accepted here Learn more about OpenID