Stop people hotlinking your pics

Don’t you just hate it when you see your photos or hand crafted graphics popping up on other people’s sites?

Well you can’t do much about people copying those kind of files and hosting them on their own site, but we certainly can stop them just lifting everything and using things that are hosted on your server – or ‘hotlinking’ as it’s called.

This tactic is bad news for you because someone else gets the glory and all you get is the bandwidth bill.

Well, now we have a saviour in the form of the .htaccess file. (If you don’t know what a htaccess file is, click here for more info). All you need to do is put this handy bit of code in there and pop it into the root of your site, then anyone who tries to steal stuff will get a replacement picture of your choice instead:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?YOUR_DOMAIN_NAME\ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteCond %{HTTP_REFERER} !msn\. [NC]
RewriteCond %{HTTP_REFERER} !yahoo\. [NC]
RewriteRule .*\.(jpe?g|gif|bmp|png|jpg)$ /images/DONT_STEAL.jpe [L]

Obviously you need to change YOUR_DOMAIN_NAME to the domain you are actually using and you need to change DONT_STEAL to the name of the image you want to give them instead.

Don’t forget that the special picture you create needs to be saved s a .jpe (not .jpg or .jpeg) and try not to be too rude with the message that you will display on their site.

If anyone tries to steal my stuff, here is what will display on their site instead of the picture they tried to ‘borrow’:

Ha ha, brilliant. Get off my stuff!

Feel free to try it. (should just show just the image on your site, not the border or caption)

This has come in very handy on some of my client’s sites.

Thanks x

Massive props go out to David Airey on this one –