Prevent hotlinking of your images using htaccess

By

If you suddenly experience a lot of traffic to your images that are not coming from your site, it’s often because of hotlinking. If you’re on limited bandwidth this can be a real pain. Here’s an easy way to prevent it using your .htaccess file. So here is how to do it in four lines:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ http://29.media.tumblr.com/tumblr_ltn3afEByB1r3arh5o1_100.gif [NC,R,L]

If you want more sites to be able to implement your images, you can add more lines like this one:

RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourotherdomain.com [NC]

The image in RewriteRule \.(jpg|jpeg|png|gif)$ http://29.media.tumblr.com/tumblr_ltn3afEByB1r3arh5o1_100.gif [NC,R,L] should not be a picture on your domain, as your blocking will block that too. And all kinds of bad stuff happens! Just don’t do it.

That’s all that you need to do, simple right? 🙂




Respond!