Stop image hotlinking

When other people link to your images directly this can put an unwanted, additional strain on your servers - it is not just an annoying, unfair practice to use your intellectual property.

That practice is called image hotlinking and you can disable it by adding some code to your .htaccess file.

Let's say, that your site is running on the domain "" and you have a file prepared for your unwanted hotlinkers, called "placeholder.png" placed on another site, let's say "". This picture can contain anything, from a warning to your hotlinkers, reminding them that they are doing something wrong, or can be a simple empty image. It is important, to keep this file small - ultimately you want to minimize the unwanted traffic. And be sure, that the placeholder image is not hotlink-protected ;) otherwhise you can initiate an endless loop!!

The code to insert in your .htaccess file is like this:

RewriteEngine on
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)? [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ [NC,R,L]

This code checks if the website that’s trying to load your images corresponds to the URL on the third line ( If it doesn’t, and they’re trying to load an image file that uses one of the formats listed below, it’ll load placeholder.png instead.