Add hotlink protection for images with .htaccess

Add the following to file .htaccess in your virtual site root:

RewriteEngine on

RewriteCond %{HTTP_REFERER} !^http://droidozone.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://droidozone.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.droidozone.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.droidozone.com$      [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://goodbyeleecher.droidozone.com/ [R,NC]

Here, .jpg, .jpeg, and certain other file formats are checked for hot linking of images. If detected, they are redirected to alternate url, which chides the leecher.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.