Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite won't add query string

apache2 mod_rewrite won't add query string

         

gnm123

7:09 pm on Oct 10, 2007 (gmt 0)

10+ Year Member



Greetings...

I am trying to get a rewrite rule to change a url such as:

http://www.example.com/foo/123/abc/456 to:

http://www.example.com/foo/foo.swf?domain=123&tile=abc&ord=456

I have a single rule (in an .htaccess in the /foo/ directory):

RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ /foo/foo.swf?domain=$1&tile=$2&ord=$3 [L]

The rewrite log seems to be telling me that it's doing what I want

192.168.xx.xx - - [10/Oct/2007:11:59:37 --0700] [www.example.com/sid#91c6b48][rid#91e3090/initial] (2) [per-dir /var/www/html/foo/] rewrite123/abc/456 -> /foo/foo.swf?domain=123&tile=abc&ord=456
192.168.xx.xx - - [10/Oct/2007:11:59:37 --0700] [www.example.com/sid#91c6b48][rid#91e3090/initial] (3) split uri=/foo/foo.swf?domain=123&tile=abc&ord=456 -> uri=/foo/foo.swf, args=domain=123&tile=abc&ord=456
192.168.xx.xx - - [10/Oct/2007:11:59:37 --0700] [www.example.com/sid#91c6b48][rid#91e3090/initial] (1) [per-dir /var/www/html/foo/] internal redirect with /foo/foo.swf [INTERNAL REDIRECT]

However, it appears that the query string is not being appended to the redirect... I am not getting the correct output in the browser, in fact, it seems that it is just being rewritten to:

http://www.example.com/foo/foo.swf

Also, if i change the rule to redirect:

RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ /foo/foo.swf?domain=$1&tile=$2&ord=$3 [L,R]

It does in fact work, and I am redirected to

http://www.example.com/foo/foo.swf?domain=123&tile=abc&ord=456

Does anyone know why the query string is not being added when it's a transparent rewrite?

[edited by: jdMorgan at 10:07 pm (utc) on Oct. 10, 2007]
[edit reason] example.com [/edit]

jdMorgan

9:29 pm on Oct 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's the difference between a redirect and a rewrite; The redirect involves the client, and the rewrite does not. You will never get any indication in the browser that an internal rewrite has taken place, and in almost all cases, this is the desired effect.

If the output of this rule needs to be proxied to a back-end server or passed through any other modules, be sure to use the [PT] flag on the rule. But before changing anything, and ignoring the browser address bar, is the correct content being served?

Jim

gnm123

9:51 pm on Oct 10, 2007 (gmt 0)

10+ Year Member



The rerwrite is what I want, but the rewrite is is *not* serving the correct content.

The exact same rule as a redirect *does* return the correct content (the same RewriteRule line but with [R] added).

There is no proxying involved (should there be?, and its not being passed to another module.

If I leave the RewriteRule to rewrite (not redirect) (no [R]), it returns just the foo.swf, as if i had just sent a request for [domain...]

jdMorgan

10:11 pm on Oct 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's abnormal behaviour... Have you asked your host?

Also, be sure that no other RewriteRule pattern will match the URL-path output by this rule; While the [L] flag stops mod_rewrite processing for this pass through the code, mod_rewrite in .htaccess behaves recursively, and will re-execute until it makes a pass where no further rewrites or redirects are invoked.

Jim

gnm123

11:08 pm on Oct 10, 2007 (gmt 0)

10+ Year Member



Heh. I am the host.

I just wrote a quick php script to see if I could duplicate the error, but PHP has no problem with the exact same rule.... so it's looking like the problem is with the swf...

I'm guessing maybe that rewrites (i.e. "Internal Redirect") somehow behave differently than a normal GET request, and that is throwing off the swf.

jdMorgan

12:18 pm on Oct 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It sounds like the .swf is GETting the query from an internal server variable that is not being updated by the RewriteRule, so PHP works and swf doesn't. You might want to modify the swf code (if possible) and/or report this problem to the developers.

Jim

g1smd

11:44 pm on Oct 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Be aware that [R] serves a 302 redirect. For a 301 redirect you will usually need [R=301] instead.

I know you want a rewrite here, so no [R] is needed at all, but just wanted to point out what [R] will do for you.