Disallow hotlinking by using .htaccess
The .htaccess file located in your /public_html/ directory is a very useful file to configure how your website behave. A lot of people use the .htaccess file to do URL redirection. For example, they want users to access their site without ‘www’, so they will insert the redirection codes inside the .htaccess file so that any users who access their site with ‘www’ will be redirected to their domain without ‘www’.
By taking advantage of the URL redirection with .htaccess, you can actually do more useful stuffs, such as disallowing external users to hotlink your images from their site.
What is image hotlinking?
Hotlinking is a method of linking images directly from your website into their own website. This method is usually referred to as ’stealing’, because doing hotlinking will take up your website’s bandwidth instead of theirs.
Let’s say your domain is yourdomain.com. Another user found an interesting image that you posted in your website, so he/she decided to ’steal’that image by doing hotlinking in their own website’s HTML, such as below:
<img src=”http://www.yourdomain.com/images/myimage.gif” />
By inserting the code above into their own website, the image “myimage.gif” from your website will be displayed in their own website. Because of this, everytime that person’s website is visited, the image will load in their website but it is your bandwidth which is actually being used - therefore, the term “bandwidth stealing” was invented 
How to avoid hotlinking?
All you need to do is edit your .htaccess file and add the following codes:
====
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .(jpg|jpeg|png|gif)$ http://img371.imageshack.us/img371/6905/bandwidthzn9.jpg [NC,R,L]
====
Now when people hotlink your image into their website, the image will not show up. Instead, it will be replaced with the “Stop Stealing Bandwidth” image, or any other image you specify in your .htaccess configuration.
You may change the imageshack URL to display any other image you want when external people hotlink to your image. It is best that you host that image on some other external image hosting service, such as ImageShack, or else it beats the whole idea of disallowing hotlinking.
That’s basically it! 







Leave a Comment