One of the sites that I manage was sucking an inordinate amount of bandwidth over the past week or so.

The raw access logs showed that an image that I was hosting was being referenced on a number of different sites. Preventing this from happening is an easy fix:

Locate your .htaccess file and add the following lines:


# Begin Disable Hotlinking of Images
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?YourDomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www.)?feedburner.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(feeds.)?feedburner.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www.)?facebook.com/.*$ [NC]
RewriteRule .(gif|jpg|js|css|png)$ - [F]
# End Disable Hotlinking

Don’t forget to replace “YourDomain.com” with your domain name.

This particular update will prevent anyone from hot linking images from your site. If you want to do the same for additional files (such as JavaScript, CSS, etc) you can add the file types:

RewriteRule .(gif|jpg|png|css|js)$ - [F]

Easy enough.