/home/jeff/blog

Sucking away valuable moments of your life ...

No More Hotlinking Images

| Comments

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:

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

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

1
2
3
4
 RewriteEngine on
 RewriteCond %{HTTP_REFERER} !^$
 RewriteCond %{HTTP_REFERER} !^http://(www.)?sitename.com/.*$ [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.

Related Posts