Disable hot linking in Apache

By Nisse Pettersson at July 17, 2009 03:42
Filed Under: Technical
Share on Facebook

I've came across a problem where I don't want it to be possible to download content from the web server. This is called hot linking or some say bandwidth stealing. This can be prevented by using a .htaccess in the directory.

In this file you add the following lines.

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

The forth line will redirect the user to the URL stated. Happy hacking!