How to do location /test/place?id=2

P.V.Anthony anthony at mindmedia.com.sg
Fri Oct 18 05:17:52 UTC 2019


On 18/10/19 12:20 pm, Patrick wrote:

> Without a map, try starting with:
> 
> if ( $uri?$args = /test/place?id=2 ) {
>      rewrite ^ http://new.example.com/${uri}?${args}? last;
> }
> 
> Then as the site migration continues turn that `if' test into a regexp
> that will match the migrated components.

I can get the following to work.

if ( $uri = /test/place ) {
       rewrite ^ http://new.example.com${uri}?${args}? last;
}

and this also works.

if ( $args = id=2 ) {
       rewrite ^ http://new.example.com${uri}?${args}? last;
}

Unfortunately I cannot get the suggested solution to work. Did I miss 
some setting or quotes?

 > if ( $uri?$args = /test/place?id=2 ) {
 >      rewrite ^ http://new.example.com${uri}?${args}? last;
 > }


Tried the following and it works but is it safe?

if ( $request_uri = "/test/place?id=2" ) {
       rewrite ^ http://new.example.com${uri}?${args}? last;
}

P.V.Anthony


More information about the nginx mailing list