«
»

Technology & Science

Hotlinking Redux

05.09.08 | 1 Comment

Do not hotlink

Well, I’ve tried being nice, I’ve tried being reasonable, I’ve tried everything I can think of to stop people from hotlinking to images on this site. It’s all to no avail, so I’ve implemented an extremely rude picture that chastises the hotlinker and is rude enough that hotlinking will likely reduce to nothing. It’s a shame that it had to come to this, but I don’t know what else to do.

In case you want to prevent hotlinking, here’s how. Create a .htaccess file in your images directory on your webserver. Ensure that mod_rewrite is functional on your webserver. Then put the following contents in your .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https://(www\.)?YOURDOMAIN.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ https://YOURDOMAIN.com/SUBSTITUTEIMAGE.jpg [R,L]

The trick here is to make sure that the substitute file you’ll serve is not in the same directory you’re preventing access to and that you replace YOURDOMAIN with whatever your website is and replace SUBSTITUTEIMAGE with what you deem to be an appropriate message to share with the offender. Good luck.

1 Comment




«
»