How to stop bandwidth stealing with htaccess file

Bandwidth Stealing or Hotlinking is a scenario when somebody uses a file from your site directly to his. This results in the consumption of your bandwidth. Many people do not realize but this is a common problem and as there is no direct way to know about it, we never get to know about it. This scenario can not only lead to your hosting banning your site as it’s out of bandwidth but your content is getting stolen too. If you want  you can read about Top Five Ways to stop content stealing

What is hotlinking?

Hotlinking is a scenario where some other site uses files hosted on your site. This results in bandwidth stealing as every time the hot-linked page is viewed, images or files are requested from your server hence your bandwidth is used.

How to find if my files are hotlinked?

There is no direct way, But when I asked my hosting about it, they said we can check our web stats and find out how much bandwidth is being used by which page or other things. If you something very high try to find out where it is linked.

How to stop hotlinking using .htaccess file?

This can be helpful for PHP based sites and WordPress based sites.

Before you write your own rules, enable the hotlinking protection enabled, and then write into .htaccess file. I did it reverse and my site gave Error 500. Be Careful. In case if something goes wrong just remove the .htaccess file and replace it with the original one ( Did I forgot to say backup your .htaccess file first ? Please do it ) and be sure mod_rewrite is enabled. Ask your hosting about it.

There are three ways of doing it.

  1. Ban all hotlinks
  2. Ban one particular hotlinking
  3. Show a different image to one particular hotlinking

I followed the second step as I came to know who was stealing my content. Here is the code I used

# BEGIN WordPress

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^* [NC]
RewriteRule \.(gif|jpg|js|css|JPG)$ - [F]

# END WordPress

You can replace XYZ with the site who is stealing your bandwidth and in second-line, you can restrict files by extension or types. Remember This is to just avoid one hot linker.

Here is the link to the complete guide of all the three scenarios. Stop Image Hotlinking using .htaccess and this article How Do I Stop Hotlinking and Bandwidth Theft? can explain your meaning of each line and terms being used. I would recommend using the first link for implementing the code and the second to understand it better. ( I got some problem while using the code from the second article)

I don’t have PHP based Site or WordPress What should I do?

Not sticking to just WordPress but every hosting has a Hot Link Protection feature. You can query your hosting about it and ask how to enable it. Just remember, you should allow your site url to access it.

Since I faced this problem, I wanted to share it with you all. I hope this helps many others.


Please enter your comment!
Please enter your name here