Web Hosting Forum - Net Hosting Talk

We are a community of individuals and businesses passionate about web hosting. Let's build, learn, and grow together.

Tutorial What is Hotlinking and how to prevent hotlinking with a .htaccess file


NHT Manager
Hi All,

Have you suffered the consequences of Hotlinking? Do you want to know how to avoid it in htaccess? I will tell you what Hotlinking is and how to prevent it so it does not harm your website.

What is Hotlinking?

Hotlinking uses another site's bandwidth by displaying its website asset – like an image, video, or audio file – on a different website via a direct weblink.

This causes the files that are linked to load on our website, which is the one that hosts the files, instead of on the website that has made the Hotlinking. Therefore, they use our server's resources, saturating it with requests and consuming bandwidth.

What happens if our server is saturated with requests?
When the server becomes saturated, it can become unstable or even crash and become inoperative, making our website inaccessible.

It also negatively influences SEO since our page's loading time will be longer, and this is one of the most important factors for Google when it comes to positioning itself in its search engine.

And what about bandwidth?

What happens when our bandwidth is consumed depends significantly on the hosting we have contracted. It may be that the page directly stops working, does it more slowly, or you may be charged surcharges for exceeding your contracted plan depending on the company with which you have acquired your web hosting service.

Avoid Hotlinking using htaccess

We can choose many strategies to protect our website from Hotlinking.

Putting watermarks on images or making them opaque are some ways we can help protect ourselves from these practices, but they will not prevent any use of the page from using the files this way.

The most effective way in which we will make sure that nobody can externally access our files will be to avoid Hotlinking through the htaccess file.

In this way, modifying just a few lines of code in this file will prevent users from accessing the files externally to our website.

Unfortunately, bandwidth theft through Hotlinking is more common than we sometimes think, especially by users who host their websites on sites with minimal spaces or free hostings that link directly to your site's files. Web (images, videos, etc.).

To do this, we must locate the htaccess file in the file explorer inside the control panel of our hosting. Once we locate it, we will proceed to edit it by adding the following lines of code:

You don't have permission to view the spoiler content. Log in or register now.

Replace example.com on line 3 with your domain name.

In case you do not see yourselves with the confidence to change any of the code, there are hotlinking generators such as hotlinking code generators, which, after entering the necessary data, will give you the complete code prepared to copy and paste into your htaccess.

We hope that this article about what Hotlinking is and how to protect yourself from the threats it implies has served you.

How about you? How do you usually protect your website against malicious activities such as Hotlinking?
  • Advertisement
  • Advertisement