Thursday 2 August 2012

Prevent hotlinking Apache

Sometimes other sites use images,video etc from your site. This is called hotlinking or bandwidth theft.
Hotlink protection can save you lots of bandwidth by preventing other sites from displaying your images. For hotlink protection, you need to create some rules in Apache .htaccess file. Put the below lines in .htaccess.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?drupalssl.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?drupalsample.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

The above rule prevent use of images having extensions jpg,jpeg,png,gif other than drupalssl.com and drupalsample.com. Even if they use it, they will just see the image placeholder. if you want to show some other image when they try to hotlink, last line can be changed to.
RewriteRule \.(jpg|jpeg|gif)$ http://www.drupalssl.com/Test3.png [NC,R,L]
References:
http://altlab.com/hotlinking.html/
http://www.htaccesstools.com/hotlink-protection/

No comments:

Post a Comment