Hot Linking and Protection in HTACCESS

In this article we will discuss about hot linking and how to protect your resources from hot linking.

Let’s discuss about what is hot linking.

Hot linking means bandwidth theft. Direct linking of a website’s resources (image, video, file, etc) on some other website. Whenever you visit any site the site resources are downloaded from the hosting server to your browser. And the amount of data transferred over a period of time is bandwidth. If your website images are directly linked and being displayed on some other site, that will be downloaded from your hosting server and increase your bandwidth. That’s an issue and billed extra.

For example you have a site site1.com and site2.com uses an image from your site

<img src=“//site1.com/images/image.jpg” /> and just consider the image size is 500kb and loaded on site2.com 1000 times in a month. You are just loosing 488MB of bandwidth in a month.

Now let’s discuss how to prevent hot linking.

Many hosting providers provide hot link protection in the hosting plan.

I am going to show a quick way to prevent hot linking using .htaccess

We can easily find out where that traffic is coming from by looking http_referrers data.

We can check the referrer and block if that’s not coming from your website using the below rules.


RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)example.com/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|bmp|zip|rar|mp3|flv|swf|xml|php|png|css|pdf)$ - [F]

Hope this helps.

Share this Post