views:

28

answers:

2

If I load an SWF with a query string at the end, like:

object.swf?this=that

... then "this" is properly recognized as a flashvar within the flash object.

But, if I set "this" via mod_rewrite, as in:

RewriteRule ^object$ lib/object.swf?this=that [QSA,NC,L]

... then "this" is undefined.

I even wrote a little PHP script to dump the contents of $_GET (changed the rewrite target temporarily), and I'm positive that the rewrite rule is working.

Any help greatly appreciated.

mod_rewrite clarification:

To demonstrate the strangeness of the problem, let me temporarily change the rewrite target to "object.php", so the rule now reads:

RewriteRule ^object$ lib/object.php?this=that [QSA,NC,L]

I created object.php in the /lib/ directory with the following line:

<?php echo '<pre>'.print_r($_GET, true).'</pre>'; ?>

Then, when I navigate to /object, I get the following output:

Array
(
    [this] => that
)

This demonstrates that the rewrite rule is working as expected.

Still, when I change the rewrite target back to the SWF, "this" is not recognized as a flashvar.

(I'd definitely check the rewrite log to make sure, but I don't think I have access to it on the Media Temple server I'm using.)

A: 

Lets break this down to find the problem.

Check your rewrite log RewriteLog "/usr/local/var/apache/logs/rewrite.log" to see what the rewrite rule is doing.

Take a look at the URL Rewriting guide: http://httpd.apache.org/docs/1.3/misc/rewriteguide.html to make sure nothing is missing from your rule.

It seems that your rewrite rule is changing something. I would test different rewrite rules as such until I got a failure:

Example: Rule 1: www.mysite.com to www.mysite.com/flash Rule 2: www.mysite.com/flash to www.mysite.com/myswf.swf etc...

The point is to find out if it will work with mod rewrite under some circumstance and not others or not at all.

Todd Moses
JKS
+2  A: 

I believe that it's working exactly as it's meant to. When you're rewriting the URL, you're performing the transformation on the server, and the process is entirely transparent to the client. While this isn't a problem for your PHP script, which runs on the server, it is problematic for your Flash content, which runs on the client.

I suspect that the reason that adding a query string works is that the Flash player is able to parse out the relevant information from the request when it loads the movie object. However, when you use mod_rewrite, the modified request is not available to the player, so it is not able to extract the information that you need.

If you wanted to have the URL without the query string, it is possible to examine the request path of the loaded file inside of the SWF, so you could simply redirect to the Flash file without a query string on the server, and then inside of the SWF parse out the information that you're currently getting with mod_rewrite to determine what content to load internally. I'd have to brush up on my ActionScript to give you a code sample, but if you're interested I'll see what I can do.

Tim Stone
Makes perfect sense now, thanks for such a detailed answer.
JKS