What are hotlinks & How to enable hotlink protection

In the field of computing, Hotlinks refer to the process/action of using/linking to an object (Can be an image, pdf, video) on another server or another computer. This process is also termed as inline linking.

In simple terms, hotlinking an object means a person uses & displays an image on his/her personal internet site by linking & obtaining that image (From another website) every time it is needed, rather than saving a copy of it on their own server where the website is hosted.

So, instead of loading a picture on their own site, a website owner uses a link to the picture as http://example.com/picture.jpg. When the hotlinking website is loaded, the image is loaded from the other website, it uses that server’s bandwidth.

On the other hand, users get confused by the term hotlink & hyperlink. A hyperlink is any active link that on a site when clicked, takes/redirects you to another page or file on the Internet/the same website.

That’s why many users enable hotlink on their site to stop bandwidth stealing since it might also slow down their site. Hotlink protection can drain resources, when any files on your server/website are requested, the server has to check and see if the request is for a file type that is protected. If yes, then it checks and ensures that the referring URL is allowed.

How to enable Hotlink protection?

Type or Copy this at the end your .htacess file (Usually in your site’s root directory). Keep in mind to change yourdomain.com to your domain. Other sites can be added to allow them to use/access the files on your web server.

RewriteEngine on
 RewriteCond %{HTTP_REFERER} !^$
 RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
 RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
 RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?bing.com [NC]
 RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?facebook.com [NC]
 RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yahoo.com [NC]
 RewriteRule \.(jpg|jpeg|png|gif|svg)$ - [F,NC,L]

The first line opens redirection process.
The second line allows blank referrers.
The third line is for your own domain or else you might end up blocking images for your own site.
The rest of the lines allow sites like google, yahoo etc to see & index your content (You do not want to disable that).