• Blogging
  • Freebies
  • Freeware
  • How-To
  • Make Money Online
  • Mobile
  • Home >> How-To >> How to avoid Hotlinking of file and images using .htaccess hack

    How to avoid Hotlinking of file and images using .htaccess hack


    Yesterday, I posted a .htaccess hack to Block Visitors from specific IP using .htaccess

    Today, I am sharing with you one more .htaccess hack – How to avoid Hotlinking of file and images using .htaccess hack

    What is HotLinking?

    Avoid / Prevent Hotlinking of images or files (Credit http://www.conquerhosting.com)

    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.

    1. Login to your hosting service site and open code>.htaccess file. Make sure you backup the file before making any changes.
    2. 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]
    3. 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!

    IMPORTANT: This blog welcomes Guest Bloggers, Writers to also contribute by writing Guest Posts and also Make Money!. Check out our Revenue Sharing Program
    1924 readers are already subscribed to this blog! Why don't you be one of them? Subscribe to this blog via your favorite RSS feed reader or by entering your email address on the form below:





    21 Comments

    1. Lyndi says:

      I dislike hot-linkers almost as much as I dislike spammers. This little hack should sort them out. Thanks for this.

      • Nihar says:

        @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.

    2. Gagan says:

      this one is very useful, cute little trick. will help me a lot.

    3. Atul says:

      very useful post I’ll soon implement it. Never even thought of this Thanks

    4. This is awesome! Thank you for the hack, I’m going to try it right now

    5. Chetan says:

      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. 🙂

    6. Ruchi says:

      Thanks Nihar, I was looking for it that how to ban the hotlinking, I will give it a try.

    7. Ramakanth says:

      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.

    8. Laptops says:

      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,

    9. ravi says:

      Thanks for sharing this trick,i was facing this problem those leechers are killing my bandwidth,that

    10. Brian Smith says:

      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.

    11. linda says:

      Thanks for sharing,very useful tips

    Leave a Reply

    page counter
    NiharsWorld on Twitter NiharsWorld on Facebook NiharsWorld RSS Feed