Prevent Image HotLinking bandwidth stealing

Security in htaccess: htpasswd, 401 Authentication

Prevent Image HotLinking bandwidth stealing

Postby produke » 03 Oct 2006 02:22

Hot linking or bandwidth stealing is a common problem. It happens when people link to files and images on a different server, display them on their website and the bandwidth is at the other person's expense.

Code: Select all
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?askapache.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.askapache.com/hotlink.gif [R,L]




1. Activate Protection

Stop people from hotlinking to your image files.


Code: Select all
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?askapache.com/.*$ [NC]
RewriteRule \.(bmp|tif|gif|jpg|jpeg|jpe|png)$ - [F]


Replace your_domain.com with your domain name.

This starts by turning on the rewrite engine. Next, it checks the referer (where the request comes from).

If it did not come from your domain name and it is a request for a .gif or .jpg file, it will output an error message. Otherwise it will display the image as usual.

The rewrite engine is very powerful and can be used for many other purposes. This tutorial is for beginners.

2. Other Uses

This .htaccess trick can be used to protect other file types, such as .mp3, .ogg, .mpg and other files.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?your_domain.com/.*$ [NC]
RewriteRule \.(mp3|ogg|mpg)$ - [F]

The only changes in this .htaccess file are on the last line. Enter the file extensions in the brackets, do not include the dot (.). Separated them with a pipe (|).
User avatar
produke
 
Posts: 242
Joined: 25 Sep 2006 04:48

Postby produke » 02 Jul 2007 23:40

User avatar
produke
 
Posts: 242
Joined: 25 Sep 2006 04:48


Return to Security and Authentication



Who is online

Users browsing this forum: No registered users