Image Hotlinking is a common cause of increase in Bandwidth utilization of a website.
Bandwidth theft or “hotlinking” is direct linking to a web site’s files (images, video, etc.). An example would be using an
<img> tag to display a JPEG image you found on someone else’s web page so it will appear on your own site, eBay auction listing, weblog, forum message post, etc.
Bandwidth is expensive so a webmaster has to manage it carefully. One of the way to optimize the bandwidth usage is by compressing the website output. Also there are times when people will hotlink to an image hosted on your server from their blog/website which results in increase in bandwidth. For example:
Thus, for every page request for that blog, a request will be generated for this image to your server. This will eat up the bandwidth and also may increase CPU time.
So how to stop hotlinking? Well just add following code in your .htaccess file:
Your site url is www.mysite.com. To stop hotlinking of your images from other sites and display a replacement image called nohotlink.jpg placed in your images directory, place this code in your .htaccess file:
The first line of the above code begins the rewrite. The second line matches any requests from your own mysite.com url. The [NC] code means “No Case”, meaning match the url regardless of being in upper or lower case letters. The third line means allow empty referrals. Then we have few lines to Allow Search Engines like Google, Yahoo, MSN etc to crawl the images.The last line matches any files ending with the extension jpeg, jpg, gif, bmp, or png. This is then replaced by the nohotlink.jpe file in your images directory. This JPEG image is using the extension jpe instead of jpg to prevent blocking your own replacement image.
Before uploading your .htaccess file to your server make sure that there is not one there already! Applications such as WordPress use their own .htaccess file when installed, if this is the case then download the existing .htaccess file, add your extra code and then upload it back to the server.