Preventing HOTLINKING via .htaccess
Posted: 11 March 2007 08:48 AM   [ Ignore ]  
Research Assistant
RankRankRank
Total Posts:  423
Joined  03-23-2004

Hi all,

I just read the following post on excessive bandwidth use and hotlinking:
http://expressionengine.com/forums/viewthread/42606/

I didn’t want to hijack the thread so here’s my own. Like e-man in the above thread, I am unsure of where to post this but believe this may be valuable to many ee-users. I am about to build a site with lots of video feeds and my client is concerned with bandwidth use. Hotlinking could make things really bad, so I want to rule it out.

- Some sites suggest creating a simple .htaccess file and therein list the domains from which the video feeds can be accessed, i.e.

site1.org
site2
.org


However, another site suggests posting the following code into the .htaccess file (I just entered some random data):

RewriteEngine on
RewriteCond
%{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?site1.org [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?site2.org [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

Which method is more secure? Can anyone share their understanding of this code? Any thoughts or experiences on preventing hotlinking?

Profile
 
 
Posted: 11 March 2007 09:16 AM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23751
Joined  05-20-2002

I’ve always gone with an htaccess generator myself, as my htaccess/regex skills are lacking.  In short- the second approach. But in part, that’s due to ease of use and lack of skill on my part!

I’m gong to move this one up to the ‘General’ forum, as I think it may get more opinions there.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 11 March 2007 09:42 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  237
Joined  05-16-2004

I’ve used the second method on many, many sites, and it’s worked well in terms of blocking direct image links. Just remember to list all types of files you don’t want hotlinked:

RewriteRule \.(jpg|jpeg|png|gif|mp3|swf|JPG|JPEG|PNG|GIF|MP3|SWF)$ - [NC,F,L]

This rule is inherited; so if you put this rule in place on your top-level directory, all directories under it are automatically covered. (Sometimes I’ve run into a situation where someone wants to create a few buttons that *are* hotlinkable - like a branding button or what have you. My solution has been to put those buttons in their own directory, name the files with the extension “.jpeg” to boot (instead of .jpg), and create a separate .htaccess file for that one directory that disallows hotlinking to all file types except .jpeg.

Profile
 
 
Posted: 11 March 2007 09:56 AM   [ Ignore ]   [ # 3 ]  
Research Assistant
RankRankRank
Total Posts:  423
Joined  03-23-2004

Robin and Lesli, thanks for your advice! Just one more thing: The site I linked to in my original post gives the option of allowing “blank referers”. It recommends allowing those. I don’t quite seem to understand. Can anyone explain what is meant by that? I want people to be able to watch the video feed on my own site. Not on someone else’s site. So I guess blank referers should not be allowed?!

Profile
 
 
Posted: 11 March 2007 12:03 PM   [ Ignore ]   [ # 4 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  33276
Joined  05-14-2004

Blank referrers could mean someone that copies a link to your site here and pastes it in a new tab, etc.  Rather than clicking, they’re somehow entering that link (typing or copy paste or whatever).  You want to allow those, imo.

 Signature 
Profile
MSG
 
 
Posted: 11 March 2007 05:18 PM   [ Ignore ]   [ # 5 ]  
Research Assistant
RankRankRank
Total Posts:  423
Joined  03-23-2004

Thanks Lisa!
Just to clarify, we are talking about a direkt link to the video file, right? If the visitor was visiting the page the video feed was on (as opposed to just connecting to the video file) there wouldn’t be an issue, is that right? E.g.: 1) www.site1.org/issues/environmentalissue1/ and 2) www.site1.org/movies/environmental/movie1.mov. Assuming the movie in on page 1), I would want someone to be able to access address 1) but not address 2). If someone could access address 2), he/she would be able to watch the movie in an otherwise ‘blank’ browser window.

Profile
 
 
Posted: 11 March 2007 05:21 PM   [ Ignore ]   [ # 6 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  33276
Joined  05-14-2004

I do believe it’s directly the video file. You could modify the .htaccess and test it, that’s what I’d do.

 Signature 
Profile
MSG
 
 
Posted: 11 March 2007 05:46 PM   [ Ignore ]   [ # 7 ]  
Research Assistant
RankRankRank
Total Posts:  423
Joined  03-23-2004

I see! Thanks for that! I will play with it and report back!

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 66471 Total Logged-in Users: 40
Total Topics: 84869 Total Anonymous Users: 20
Total Replies: 455376 Total Guests: 213
Total Posts: 540245    
Members ( View Memberlist )