views:

146

answers:

3

I'm attempting to use mod_rewrite to clean up the URL's to a flash video player. First, here is the original URL that I'm trying to rewrite to:

library/player.swf?path=path-to-file.flv

The above URL works perfectly fine when I access it directly. I have coded the swf to automatically grab the path parameter and play the video. No problems there. Now here is my attempted rewrite rule:

RewriteRule ^player/(.+)$ library/player.swf?path=$1 [QSA,L]

When visiting the url player/path-to-file.flv, I get the swf but no video loads. I set up a popup window in the flash to tell me the path name for debugging purposes, and it looks like the path isn't being passed at all.

On the other hand if I use the exact same rule but point it to a test.php instead of player.swf, the test.php file is able to echo out the parameter.

So the question comes down to, am I doing something incorrectly or is it impossible to send a query string to a swf via mod_rewrite?

+1  A: 

It is impossible using the mechanism you are attempting there. Remember that a .swf is processed client side, so all the server is doing is sending the file to the client. The query-string is irrelevant to this, and the server will essentially just ignore it.

It is possible to read query string parameters in a .swf file, but again not with a directly served file. This is again due to how these things work... to access the parameters, the .swf needs to be embedded in a DOM and it will then be able to access the DOM and obtain the query string through the DOM interfaces, so will be served as part of a html page.

If it's any help, a way I've seen quite frequently to get the parameters into a .swf file is to use a PHP script to dynamically create the tags and set parameters in this fashion corresponding to query string parameters, database variables, etc. The entire page is then served, and the parameters are passed into the .swf app when it is being run by the flash runtime.

workmad3
Swf files don't necessarily have to be wrapped in HTML to access query string params. I'm using the Application.application.parameters object in Flex and it works great, even without an HTML wrapper. All I have to do is point my browser to player.swf?path=whatever.flv and everything loads as expected.That said I think I agree with your first paragraph. Something about mod_rewrite being server side and the swf being client side is causing my parameters to never get passed.
Greg W
ah, I guess the browser creates some form of DOM for the flash player to access even without some HTML wrapping it up :)
workmad3
Ok, that makes sense. Webkit's inspector is indeed showing a simple html body structure being thrown in automatically.
Greg W
A: 

if you add a [R] to the directive flags it will do an external redirect which the client should see.

Josh
But then the URL hasn't been cleaned up at all. It's the same ugly URL as always and there's no point having a redirect...
workmad3
+1  A: 

I voted up Workmad3's answer, but I wanted to go ahead and post this alternative solution as well. For my rewrite rule, I used a similar rule as I posted in the original question.

RewriteRule ^player/(.+)$ library/player.swf [L]

Then in the actionscript, do something similar to this:

var url:String = String(ExternalInterface.call("function(){return document.location.pathname.toString();}"));
var urlParts:Array = url.split("/");
var length:Number = urlParts.length;
var file:String = urlParts[length-1] + ".f4v";
Alert.show("The filename is: " + file);

The above will simply post the filename in an alert window, but the point is that you could theoretically use this to make "clean" urls. It feels a little hackish, but you could make it work.

Greg W