Preventing Hot Linking

Hot linking, otherwise known as bandwith stealing, is a horrible crime in the webmaster's community. It occurs when someone links directly to images, css, or javascript files not on one own's server, thus enjoying those objects without having to pay for them, using up the money of the unlucky site owner instead.

To help prevent this, you can use a .htaccess file, with Apache's module mod_rewrite enabled, to either 1)block or fail the request or 2)redirect the hotlinker, for example, to an angry message when hotlinking occurs.

The code below will protect images, CSS (.css), and Javascript (.js) files on your site. Simply add it to your file and then upload it to either the root-directory or one sub-directory of your site.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC]
RewriteRule \.(gif|jpg|js|css)$ - [F]

Replace yourdomain.com with the domain of your site. This will generate a failed request when people try to hot link your files, thus showing a broken image.


RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.mydomain.com/angrymessage.html [R,L]

Again, replace yourdomain.com with the domain of your site. This code, instead of showing a broken image, will redirect the hot linker to angrymessage.html.


And there you have blocked hot linkers! Congratulations! =)


[Back]


Custom Search


Choose Your Skin:

Site
 
Designs
 
Graphics
 
Scripts/Reads
 
Tutorials
 
Affiliates
 
Other
 
Skins
 
eXTReMe Tracker