User Guides Avoiding HotLinking of Images/Files. on Apache/Tomcat

Suppose you are a webmaster u know the value of Bandwidth.. There can be people who can hotlink your images/files thereby stealing your bandwidth.. In this case the actual traffic goes to the one who steals, but you need to pay the price of bandwidth..

Now this tut is to help you to avoid people hotlinksing your files, if u r using Apache Webserver.

Open the .htaccess file on your server. This is a configuration file used to set permission for access made on your files.

The following code can be used on ur .htaccess file to avoid Hotlinking:

<Files .htaccess>
deny from all
</Files>
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://YOURDOMAIN.com.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.YOURDOMAIN.com.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://YOURIPADDRESS.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.YOURIPADDRESS.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.google.com.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://google.com.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://216.239.*.* [NC]
RewriteRule .*\.(gif¦jpg¦jpeg¦zip|pdf|exebmp¦png¦mpg¦mpeg¦avi¦wmv¦mov¦asf)$ - [F]
Using the above code, you allow the files on your site to be linked only from your site and Google (216.239.*.* is Google's IP). If you want, you can also remove the lines with Google's URL.

<Files .htaccess>
deny from all
</Files>

This code is to prevent people from seeing the contents of ur .htaccess file itself.

the RewriteCond checks the HTTP referer which has linked to the file/image to be downloaded. It checks whether the file format is as set in RewriteRule, and if it does, it checks the domains to which permission has been granted. Incase of Hotlinked files, Access is denied.

Hope this one helps..!
 
Back
Top