It’s always a pain in the ass if you are running a gallery site or any other site that contains quality images that other people would easily place on their site. If people hotlink images from your domain your bandwidth will be used up and they will get the honour of having the image. We can solve this by using mod_rewrite. If we use mod_rewrite to check the referrer we can easily make sure that there is no hotlinking. Only thing we have to do is check if the referrer is your own domain or not, and if it isn’t you can display a default image where you make yourself clear on not to leech images from your site.

The following code should be placed in the images folder you would like to protect from hotlinking:

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On
   RewriteCond %{HTTP_REFERER} !^$
   RewriteCond %{HTTP_REFERER} !domain.com
   RewriteRule \.(gif|jpg|jpeg|png)$ nosteal.jpg [L]
</IfModule>

Where you have to replace domain.com by your domain and the nosteal.jpg picture is a default picture that will be shown if someone wants to load a hotlinked image.

Post a Comment