Try_files and GET variables

Hello,
tried to replace the webserver config to use try_files instead of
rewrites (on 0.7.46), it kinda works but I get some garbage in
QUERY_STRING on the php fastcgi backend - so php doesnt see any GET
variable.

The config is simple:

location /tmp {
try_files $uri /index.php;
}

When I open http://myserver/tmp/?var=1 and dump the $_SERVER variables
‘REQUEST_URI’ is correct - ‘/tmp/?var=1’ but QUERY_STRING
gets something like ‘H‰H=�’ (non-printable chars)

If I change the nginx config to named location everything works as
expected (all the GET variables are passed and QUERY_STRING is
correct):

location /tmp {
try_files $uri @tmp;
}

location @tmp{
fastcgi_pass 127.0.0.1:1026;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
}

Where is the catch?

wbr
Reinis R.

On Mon, Mar 30, 2009 at 04:47:21PM +0300, Reinis R. wrote:

}
(all the GET variables are passed and QUERY_STRING is correct):
}

Where is the catch?

The attached patch fixes the bug.

The attached patch fixes the bug.

It fixed the garbage part then again QUERY_STRING is now empty at all…
Or is this expected?

In short what I try to archieve is this - if you have:

location /tmp {
try_files $uri /index.php;
}

And open something like http://myserver/tmp/somecategory/another/?id=234
php still gets ‘id’ as normal GET variable…

The rewrite or error_page alternative would be:

rewrite ^/tmp/(.*)$ / last;

location /tmp/ {
error_page 404 = /index.php;
}

I somehow see this conflicting if you specify something like this in the
config

location /tmp {
try_files $uri /index.php?q=$request_uri;
}

Then again it gets messy if you want to split the query_string on php
side and assign all the variables… Besides try_files looks
way more superior than both previous approaches…

wbr
rr

If you want to preserve query_string, then you should use

try_files $uri /index.php?$args;

Thanks, missed this!
Together with the patch now works perfectly…

rr

On Mon, Mar 30, 2009 at 06:14:25PM +0300, Reinis R. wrote:

}

And open something like http://myserver/tmp/somecategory/another/?id=234
php still gets ‘id’ as normal GET variable…

If you want to preserve query_string, then you should use

try_files $uri /index.php?$args;