htaccess Elite

.htaccess tutorial


All times are UTC [ DST ]





Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Prevent Image HotLinking bandwidth stealing
PostPosted: 03 Oct 2006 02:22 
Offline
User avatar

Joined: 25 Sep 2006 04:48
Posts: 242
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:
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:
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 (|).


Top
 Profile  
 
 Post subject:
PostPosted: 02 Jul 2007 23:40 
Offline
User avatar

Joined: 25 Sep 2006 04:48
Posts: 242
Also see Redirect Hotlinking problem


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron
Powered by phpBB