How to prevent hot linking ?

Printer-friendly versionPDF version
No votes yet

 

What is hot linking?

Bandwidth theft or “hotlinking” is direct linking to a web site’s files (images, video etc). Have your ever noticed your site is having small amount of visitors comparing to the bandwidth it is consuming??

It may happen because other websites are linking your image files, videos and other resources direclty from your site without uploading them in their server. This gives them the benefit that they donot need to expense their bandwidth from their host because they are stealing that from your site.

So to prevent abuse of your bandwidth you must prevent hot linking so that other sites cannot directly link off your files.

To do this you must use an apache mod rewrite code in your “.htaccess” file. This techinque will prevent direct linking to image video and other high bandwidth consuming files being linking directly by any other host than yours. When resource files are directly linked from other host it will redirect all those links to a small image file saying “No hot linking!”.

How to do this?

Add this code in you “.htaccess” file.

# Prevent Hot Linking
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?dscripts\.cc/ [nc]
RewriteRule .*\.(gif|jpg|png|zip|swf)$ img/hotlink.gif [nc]


Lets see what happens in this code.

This two line below sets an condition for what to do if the referrer page is not from “dscripts.net”.

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?dscripts\.cc/ [nc]

And this line below say what would be returned file for the file with gif, jpg, png, zip or swf extensions. If the any other site link your any resource then a fake image at “img/hotlink.gif” will be returned to them.

 

RewriteRule .*\.(gif|jpg|png|zip|swf)$ img/hotlink.gif [nc]