Web Design Blog

This is where we store some of our Web Development thoughts, tips and tricks, just because we like to share.

Htaccess: Prevent People Hotlinking Your Images

Here’s some Htaccess code that will prevent people from hotlinking images hosted on your server. Simply change the domain to yours and then apply the code to your .htaccess. It’s as easy as that.

1
2
3
RewriteCond %{HTTP_REFERER} !^$  
RewriteCond %{HTTP_REFERER} !^http(s)?://(.*\.)?brightcherry.co.uk [NC]  
RewriteRule \.(jpeg|jpg|gif|png)$ - [F]

The code is basically saying that all jpg, gif and png files hosted on brightcherry.co.uk can only be displayed on brightcherry.co.uk. Anyone else that tries to hotlink it will see a X.

Why would you want to prevent people from hotlinking?

There are many reasons, but the main two I can think of are:

  • Prevents copyright infringement
  • Reduces data transfer. If someone hotlinks one of your images onto a website that receives heavy traffic, it will be your server that’s sending the data. That could specifically be costly for Admins that don’t have unlimited data transfer allowance.

22 Aug 2009 / 1 Comment / htaccess fun / by Maruf

1 Comment

  1. Milan
    30/12/2009
    1

    You should also care about caches of search engines because when people open it they’ll se X overthere too.

Leave a Reply

© 2012 BrightCherry :)