No more hotlinking images

For those who use Apache 2.x, this is a nice trick to keep people from hotlinking your images. I’ve seen a few variants of it, but this one I picked up most recently from a slashdot comment, of all places.

Make sure you have enabled mod_rewrite, then add this in your .htaccess file for any directory with images in it:

 RewriteEngine on
 RewriteCond %{HTTP_REFERER} !^http://(www.)? [NC]
 RewriteRule .* /files/goatse.jpg [NC,L]

to redirect to an awful image, or use my own personal variant:

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

which doesn’t return anything if someone else hotlinks your images. If they like your images enough, they can like them enough to save a copy on their own webserver.