Set a particular location for address starting with '?'

Cliff Wells cliff at develix.com
Thu Sep 24 05:30:46 MSD 2009


On Wed, 2009-09-23 at 19:38 -0400, mvip wrote:
> I think I've tried all different approaches for this, but here is the problem: I need to separate all URLs starting with '/?' from the remaining ones (eg /?p=12). 
> 
> I've tried a bunch of different regex matches, but none of them seems to be able to match URLs starting with a '?'. I already started a thread here (http://forum.nginx.org/read.php?11,8435), but Jim referred me over to the mailing list. 
> 
> Configuration options I've tried includes:
> 'location ^~ \?.* { proxy_pass http://blog.foobar.com;}'  and 
> 'location ~ /\?.* { proxy_pass http://blog.foobar.com;}'
> 
> The above regexes should match the request, but for some reason they don't. Could anyone please provide me with a solution here?

That's because Nginx doesn't match locations on the query string.  I
think you are most likely approaching this wrong anyway.   Judging from
the little you've described, my *guess* is that you need to proxy any
request that can't be mapped directly to an actual file:

location / {
    root /path/to/root;
    try_files $uri @myapp;
}

location @myapp {
    proxy_pass http://blog.foobar.com;
}

Regards,
Cliff







More information about the nginx mailing list