Block Hotlinking with .htaccess
Here’s something that I’ve just added to one of my sites, www.gogosuperfun.com, that some folks may find useful. It’s intended to stop people from hotlinking images and thus stealing your bandwidth.
Basically, it just blocks any domain, other than your own, from accessing filetypes that you specify.
mod_rewrite code:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com(/)?.*$ [NC]
RewriteRule .*\.(gif|jpg|jpeg|bmp)$ http://yourdomain.com/default_image.jpe [R,NC]
If that doesn’t work quite like you would have expected, try removing the line that says
RewriteEngine on
and adding
Options +FollowSymlinks
in it’s place. If that doesn’t work, take them both out and try that. If it still won’t work, try just putting both of those lines back in together. One of those combinations will work.
Just paste one of these into your .htaccess file. Most FTP applications can’t see the .htaccess file, so don’t worry… just name it htaccess.txt on your computer, upload it, and then rename it to .htaccess and it will work. Of course, you’ll need to put your domain name where it says yourdomain.com and the default image that you want to have displayed where it says http://yourdomain.com/default_image.jpe
Notice that I’ve made the default image a .jpe file, since we haven’t restricted this file type. If you we’re to make the default image one of the restricted file types (.gif, .jpg, .jpeg, or .bmp in the example above), it would just throw it into a loop since it wouldn’t be allowed to show the default image, so it would try to show the default image, but it wouldn’t be allowed… and so on…
Good luck, hope this helps someone out.








