Introduction
Have you ever noticed that some Web users use the files and images you publish with hyperlinks to your server to display them directly on their websites without your permission? This practice is known as « hot-linking » or « bandwith stealing ». It is highly desirable to protect yourself against this, as it can ultimately cause slowdowns on your sites.
This article shows you how to protect your site from hot-links via an .htaccess (hypertext access) file. The .htaccess files allow you to add simple or complex rules to the web server of your web hosting (Apache or LiteSpeed). You just need to add a few lines of code to an .htaccess file to be protected from hot-links. Note that a tool will be available in the future to perform this task automatically.
Prerequisite
Access to https://mg.n0c.com/en/.
Procedure
The procedure is explained for the N0C interface, but you can use FTP as well.
- Click Files -> File Manager:
- Navigate to the root directory of the website you want to protect. If this is your main domain, the directory is called public_html:
- Edit the .htaccess file:
- Add this code:
RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC] RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain2.com [NC] RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
In lines 3 and 4, change yourdomain.com and yourdomain2.com for your domains names (indeed, by default, all sites are blocked for automatic linking). For line 5, the images you want to block for hot- linking are in brackets (); to add more, simply separate them with the “|” symbol.
- Save the code by clicking on the Save button: