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 t开发者_开发百科he 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?
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.
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.
if you add a [R] to the directive flags it will do an external redirect which the client should see.
Wait, I believe you can, but you must write the ActionScript necessary to parse these parameters, for instance look at this example of some of my old work for a reputable company:
Don't readily have the FLA to look at immediately in front of me, but maybe my example would help shed some light on your resolve. Therefore, yeah you can dynamically parse variables from flash, but I believe it must have somewhere to write these variables as your hard cookie for keeping track of those variables, hence inability to save this information on the fly. Maybe with some server configuration and flash rewriting you could, in theory, do what you want.
Anyway, Maybe write a PHP file which is the liason for your dynamic flash to use in pushing/floating/forcing variables upon your flash movie at load, or simply call back into the dom using js to rewrite your flash based on how your feedback is from the dom. Many ways to get around stuff if you think outside the box. Feel free to look into the SWF, just don't reuse this, its clearly for example purposes only...
Example: http://www.louierd.com/soe/itemsdetails/
Now in this example I use flash for the sole purpose of sizing the height needed to display the outer HTML, this was done to have a cross-browser sure-fire way to get the right sizing across platforms and browsers, effectively. There was little support to do this using plain javascript, without having to write a lengthy javascript from scratch, no time for that, so I went with the flash, since most other project I worked on for that company at that time were pretty much flash projects in some way or another.
精彩评论