another rewrite/try files issue

brianmercer nginx-forum at nginx.us
Mon May 23 22:02:43 MSD 2011


Stelios Sfakianakis Wrote:
-------------------------------------------------------
> On 23/5/2011 1:06 πμ, brianmercer wrote:
> > Possibly this:
> >
> > location /myapp/ {
> >    root /home/stelios;
> >    try_files $uri @fallback;
> > }
> >
> > # and the "default" PHP/FastCGI
> > location @fallback {
> >    fastcgi_pass 127.0.0.1:9000;
> >    fastcgi_param SCRIPT_FILENAME
> /home/stelios/myapp/index.php;
> >    include fastcgi_params;
> > }
> >
> 
> Thanks Brian, that *almost* works (although I
> don't like repeating [most 
> of] the fastcgi config..)
> 
> But I also need to pass *part* of the original
> path as a query string. I 
> tried to following :
> 
> location @fallback {
>        fastcgi_pass 127.0.0.1:9000;
>        include fastcgi_params;
>        fastcgi_param SCRIPT_FILENAME
> /home/stelios/myapp/index.php;
>        fastcgi_param  QUERY_STRING  u=$uri&$args;
> }
> 
> 
> which works but now for the url ".../myapp/users"
> the script gets a 
> query string like this: "u=/myapp/users" whereas I
> want it to be 
> "u=/users" (i.e. remove the "base" path). Is there
> any simple solution 
> to that? (e.g. can we pass parameters to a named
> location?)
> 
> Thanks!
> Stelios
> 
> 
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://nginx.org/mailman/listinfo/nginx

Oh, I see.  Maybe this:

location ~ /myapp/(?<myquery>.*) {
root /home/stelios;
try_files $uri /myapp/index.php?u=/$myquery;
}

location = /myapp/index.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /home/stelios/myapp/index.php;
include fastcgi_params;
}

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,199965,200179#msg-200179




More information about the nginx mailing list