Forum Moderators: phranque

Message Too Old, No Replies

Rewrite request for .wmv to a .html page

         

Frank_Rizzo

10:26 am on Feb 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Someone is hotlinking to a .wmv file. I'd prefer it if they first went to a html info page and then viewed the .wmv from there.

Is it possible to use a rewrite so that any requests for the .wmv does not fire up their Media Player but sends them to a .html instead?

Something like this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^http://nn\.nn\.nn\.nnn\/movies\/funny1\.wmv
RewriteRule ^(.*)$ [mysite.com...] [R=permanent,L]

Frank_Rizzo

10:49 am on Feb 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I found something similar to what I need in another thread here:

RewriteCond %{SCRIPT_FILENAME} ([^/]+)\.zip$
RewriteRule ^.*$ www.mysitenamehere.com/download.php?file=%1 [R,L]

I've modd'd that to work in that any request for a .wmv file goes to the funny_videos.html page.

However, on that page is the true link to the .wmv and the redirect just seems to be going around in an endless loop! The page is presented but then apache see's that the page contains the .wmv and redirects it back to the .html again.

I guess I need to put the full hotlink path in the first line but then it doesn't work.

Frank_Rizzo

9:54 pm on Feb 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Any help here please guys?

jdMorgan

10:17 pm on Feb 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See this recent thread [webmasterworld.com].

Jim

Frank_Rizzo

12:42 am on Feb 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Jim, I don't think that applies in my case.

The problem is that someone has posted a direct link to a .wmv file (with ip address as the host not the domain :-( ) but I'd rather they got to that link via the info page first.

I can successfully redirect all requests to .wmv to the landing page but then on that page the .wmv 'redirects itself to the info page' kind of thing.

I guess I could get around this by converting the .wmv to a .mpg so that there is no recursive loop but I'm sure this can be done via a rewrite.

If the request is movies/funny1.wmv

then serve them

movies/funny_videos.html

jdMorgan

12:54 am on Feb 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It does apply if there is a media player involved and you're checking HTTP_REFERER.

I suppose you could try looking at HTTP_USER_AGENT. If it's a browser, redirect. Otherwise, there's not much you can do, because media players typically don't provide an HTTP_REFERER.

Jim

HughMungus

3:39 am on Feb 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for posting this quesiton, Frank. I'm kinda running into the same problem. And I've had this issue for a while with the videos on my site and audio clips on another site. I ended-up just letting people link directly (if they go through the trouble of looking at the source). What I do to compensate is change the name of the directory occassionally then redirect hotlinkers to my home page. Now that I think about it, I guess I could use mod_rewrite or whatever to change the directory, instead...

Frank_Rizzo

10:19 am on Feb 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"because media players typically don't provide an HTTP_REFERER."

Jim, I don't think I understand this. Surely the problem is not that the media player is calling the page but that an external link.

Excuse my ignorance with this but surely isn't the sequence of events this:

site www.widgets.com has a page with a link to a wmv on mysite

nnn.nnn.nnn.nnn/movies/funny1.wmv

If a user clicks that link their browser first connects to mysite. The webserver identifies the file as .wmv and instructs the users PC to fire up media player.

Therefore, we should be able to use .htaccess to trap this?

I know that I can redirect any requests for all .wmv files. Why can't I redirect for just requests for funny1.wmv?

How about another solution! Redirect if any .wmv is called and the referrer is www.widgets.com? That will get around the looping problem.

1. Apache detects a request for .wmv AND that the refferer is www.widgets.com
2. Apache redirects the user to www.mysite.com/movies/funny_videos.html
3. Apache detects that this new page is requesting a .wmv however, the referrer is now mysite.com so no redirect takes place and the file plays

Frank_Rizzo

10:53 am on Feb 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a workable solution based on some of the comments on this and the other thread.

1. Detect calls for any .wmv file and redirect to landing page.
2. Have the .wmv file renamed to .wm1

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} ([^/]+)\.wmv$
RewriteRule ^.*$ [mysite.com...] [R=permanent,L]

In funny_video1.html there is a link to play funny1.wm1 so the redirect does not do it's thing on the second request.

Also, I have it set to autoplay onthe page:

<OBJECT ID="MediaPlayer" WIDTH="320" HEIGHT="240"
CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
TYPE="application/x-oleobject">
<BR>
<PARAM NAME="FileName" VALUE="funny1.wm1">
<BR>
<PARAM NAME="autostart" VALUE="1">
<BR>
<PARAM NAME="showcontrols" VALUE="0">
<BR>
br&gt; SRC=&quot;1457.WMV&quot;<BR>
WIDTH=&quot;320&quot;<BR>
HEIGHT=&quot;240&quot;<BR>
AUTOSTART=&quot;1&quot;<BR>
SHOWCONTROLS=&quot;0&quot;&gt;<BR>
<BR>
</OBJECT>

jdMorgan

4:33 pm on Feb 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, I'll have to actually experiment with this to find out.

In the meantime, take a look at your Object code. I seem to recall that IE and Mozilla browsers use different methods, OBJECT and EMBED, and that there is a trick to make it work with both. I found a solution in the MS Media Player knowledge base several years ago, IIRC.

Are those <BR>s actually needed?

Jim