Welcome to Web Hosting Forum - Net Hosting Talk

Register now and be part of our community! When you register with the Net Hosting Talk you can join in with topics, start new topics, and generally be a part of the first level of our community. It's also quick and totally free, so what are you waiting for?

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

nhtadmin 

Administrator
Moderator
Premium Member
Messages
38
Reaction score
18
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 avoid it so that it does not harm your website.

What is Hotlinking?

The hotlinking is when someone uses an image file as yours or content on your website, introducing it as a link rather than save it to your web server itself.

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 the resources of our server, 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 for a while, making our website inaccessible.

It also has a negative influence on SEO, since the loading time of our page 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 a lot on the hosting that 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 contracted 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 of the ways in which we can help protect ourselves from these practices, but they will not prevent any use of the page from using the files in 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, which will prevent users from accessing the files externally to our website.

Unfortunately, the theft of bandwidth through hotlinking is more common than we sometimes think, especially by users who host their websites on sites with very limited spaces or free hostings, which link directly to the files on your site. 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 own domain name.

In the case of not seeing yourselves with confidence to change any of the code, there are anti Hotlinking generators such as hotlinking code generators, which after entering the necessary data will give you the complete code prepared to copy and paste in 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

Top