Yesterday I was looking at the traffic on www.shwetagupta.com and found that lot of people from myspace and other domains are referring to images hosted on my server and hence eating up my bandwidth. I was getting 40% of the requests(for images) from myspace domain. Yes! they have a huge traffic. If one has to use the images then they should download them and host them on their server instead of hotlinking to someone else site. “Hotlinking” or “Bandwidth theft” is direct linking to a web site’s files (images, video, etc.). An example would be using an <img> tag to display an image you found on someone else’s web page so it will appear on your own site, weblog, forum message post, etc. Usually personal sites don’t have that much of bandwidth to allow hotlinking of images. Also I observed that lot of people these days not only copy the content from your site but also the the images (still being served from your server i.e. leeching your bandwidth)

You can do two things to discourage hotlinking of content on your site

I Making changes in .htaccess file

Suppose all your images are in images folders ( mine are in http://www.shwetagupta.com/blog/images) then create .htaccess file in that folder with following content so that request for any image on shwetagupta.com (on any domain other than shwetagupta.com) will cause it to display a substitute image (stolen.jpg) i.e

Hotlinking of images

———-

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://yourdomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.yourdomain.com/.*$ [NC]
RewriteCond %{REQUEST_URI} !^/stolen.jpg [NC]
RewriteRule \.(gif|GIF|jpg|JPG)$ http://yourdomain.com/redirect/stolen.jpg [R]

———–

Above changes will cause it to serve http://yourdomain.com/redirect/stolen.jpg

It was just for fun :) If you don’t want to serve a substitute image (like stolen.jpg) then just put the following content in .htaccess file in your images directory
————-

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://yourdomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.yourdomain.com/.*$ [NC]
RewriteRule .*\.(gif|GIF|jpg|JPG|bmp|BMP)$ - [F]

————–

The lines above will cause the request for any image on your server to simple fail.

Few things to remember though

  • the above .htaccess should only be placed in the separate directory containing the images so that it doesn’t affect .htacess files and content.
  • mod rewrite needs to be enabled by your web host if you need to show the substitute image

You can check the effectiveness of above changes through Hot link checker

II Adding copyright text to your images

You can add copyright text (eg. copyright 2007, www.shwetagupta.com) to all your images using photoshop technique or some other tool. So even if people are hotlinking to your images, its spreading a word about your site :)

Hopefully it will discourage hotlinking of your images :)

Posted in General  |