Preventing image hotlinking

Publié le :

Important update: this entry has been revised with a much better alternative!

As some people think they can hotlink images from anywhere without giving me credit and stealing bandwidth, I had to resort to a little trickery to prevent this to happen.

For the curious, it involves the following piece of code, placed in a .htaccess file within my /images directory. I simply manage it from within MovableType via a template module linked to a file at images/.htaccess with the following module body:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?*$ [NC]
RewriteRule .*.(gif|jpg|jpeg|png)$ - [F,NC]

N.B.: if you want to reuse this code, don't forget to replace by your own domain. Obviously, this will only work on Apache or those web servers that use the same .htaccess mechanism.

Et voilà, no more hotlinking on images from this site.

Unless I specifically say otherwise, if you want to reuse an image from here, please ask first then host the image on your site.