Yesterday, i posted a .htaccess hack to Block Visitors from specific IP using .htaccess
Today, i am here again to share with you one more .htaccess hack.
What is HotLinking?
Avoid / Prevent Hotlinking of images or files (Credit http://www.conquerhosting.com)
Inline linking (also known as hotlinking, leeching, piggy-backing, direct linking, offsite image grabs and bandwidth theft) is the use of a linked object, often an image, from one site into a web page belonging to a second site. The second site is said to have an inline link to the site where the object is located.
Recently, i noticed one blogger published a post in his blog, instead of uploading the image in his own site, he linked the image of my site. Every time somebody visits his post, the image will be downloaded from my site.
There are two problems
- Loss of bandwidth.
- Image Theft (you might have created the image after a lot of hardwork and wouldn’t like somebody using your image without your permission)
There is a way in which you can stop this. It can be done by adding few lines of code in .htaccess.
Prevent Hotlinking of file and images using .htaccess hack
I am assuming that you know about .htaccess file. It resides in the root directory of your website. The root directory could be /www/, /httpdocs/ or /public_html/ directories. Any of them depends on the hosting service.
Make sure you backup .htaccess file before you making any changes.
- Login to your hosting service site and open code>.htaccess file. Make sure you backup the file before making any changes.
- Add the following code in code>.htaccess file and save the file.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://niharsworld.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://niharsworld.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.niharsworld.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.niharsworld.com$ [NC]
RewriteRule .*.(htm|jpg|jpeg|bmp|png|gif)$ - [F,NC]
- From the above line, you can make out that i am blocking hotlinking of
htm, jpg, jpeg, bmp, png, gif files.
You may remove or add any file extension that you want to avoid HotLinked.
If you know any other way, please share via comments. Hope you learned something from this post!
Technorati Tags: Hotlinking, .htaccess hack
I dislike hot-linkers almost as much as I dislike spammers. This little hack should sort them out. Thanks for this.
Lyndis last blog post..WordPress Upgrades
@Lyndi, Me too. There is one problem. If we are using google gears or importing posts along with images to our local wordpress. If this rule is there then we won’t get the images. For that we need to comment out that line temporarily.
this one is very useful, cute little trick. will help me a lot.
Gagans last blog post..TheLast84 : Latest Blogger Template From BeepTheGeek
@Gagan, This is one of the most important trick to implement.
very useful post I’ll soon implement it. Never even thought of this Thanks
Atuls last blog post..Words Women Mostly Use
@Atul, I thought you would know this. Anyways good to now that now you know it and will implement it.
This is awesome! Thank you for the hack, I’m going to try it right now
Playing with .htaccess file is really risky task, but its very powerful file in hosting. Thanks for sharing this trick.and yes backup for that file is also important.
BTW Nice theme dude.
Chetans last blog post..Google Pagerank 5 for me : Google just updated pagerank
@Chetan, Yeah it is risky but if we have a backup of .htaccess file then no problem. Just revert back the changes.
Thanks Nihar, I was looking for it that how to ban the hotlinking, I will give it a try.
@Ruchi,
Thanks and i am glad that you learned it from my post!
Thanks for sharing this trick,i was facing this problem those leechers are killing my bandwidth,that’s why currently I’m using free photo-sharing sites,anyway thanks for sharing.
Ramakanths last blog post..First Google chrome extensions are available
@Ramakanth, You are right. There are lot of ppl out there. There are also ppl who don’t know that this is leeching.
thanks for sharing this trick, i have an site from which i have noticed alot of hot linking and my bandwidth exceeds earlier because of that,Now this is going to save me,
@Laptops,
Glad that you liked the tip and you are gonna implement it. Do let me know if you have any probs.
[...] How to avoid Hotlinking of file and images using .htaccess hack [...]
[...] the past, i have shared a trick – How to avoid hotlinking of images using .htaccess hack. This trick will help you avoid [...]
Thanks for sharing this trick,i was facing this problem those leechers are killing my bandwidth,that
@Ravi, Glad that it helped you.
Ravi,i thought your copying others articles and now i see your copying comments too.
@Ramakanth, Thanks for informing. I didn’t about this. I am surprised to see that the comment is exactly same.
Smart little hack, thanks for sharing. It’s really annoying to have images hotlinked all over the place, especially if it’s done systematically by competitors.
Thanks for sharing,very useful tips