Welcome! Log In Create A New Profile

Advanced

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

Aleksandar Lazic
October 19, 2019 04:24AM
Hi P.V.Anthony.

Am 17.10.19 um 23:15 schrieb J. Lewis Muir:
> On 10/18, P.V.Anthony wrote:
>> Currently have the following url,
>>
>> https://old.example.com/test/place?id=1
>> https://old.example.com/test/place?id=2
>> https://old.example.com/test/place?id=3
>>
>> Need to redirect only id=2 to another url.
>>
>> Did the following and it works for id=2. Need id=1 and id=3 to continue
>> normally without change.
>>
>> location = /test/place {
>> if ($args = "id=2") {
>> return 301 https://new.example.com/test/place?$args;
>> }
>> }
>
> You might want to use $arg_id here (i.e., the $arg_<name> variable for
> the <name> argument). Otherwise, it won't work if any other arguments
> are given.

Have you tried Lewis suggestion with $arg_id, it looks exactly what you
searching for?

Untested:
location = /test/place {
if ($arg_id = "2") {
return 301 https://new.example.com/test/place?$args;
}
}

The documentation for arg_ is here.
http://nginx.org/en/docs/http/ngx_http_core_module.html#var_arg_

>> Or is there a way to do the following? That would be ideal.
>>
>> location = /test/place?id=2 {
>> return 301 https://new.example.com/test/place?id=2
>> }
>
> I don't think that's allowed.
>
>> Unfortunately the above does not work. What is missing?
>
> What doesn't work?
>
> I would think your
>
>> location = /test/place {
>
> block would work, although not as shown, but I assume you just left
> out the part that normally handles the request. It would handle the
> requests for id=1 and id=3 as before, and it's just the id=2 case that
> gets redirected, right?
>
> Lewis
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

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

P.V.Anthony October 17, 2019 01:02PM

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

J. Lewis Muir October 17, 2019 05:16PM

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

jeffdyke October 17, 2019 05:28PM

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

P.V.Anthony October 18, 2019 12:04AM

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

J. Lewis Muir October 18, 2019 09:48AM

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

P.V.Anthony October 19, 2019 01:56AM

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

P.V.Anthony October 18, 2019 12:02AM

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

Aleksandar Lazic October 19, 2019 04:24AM

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

P.V.Anthony October 20, 2019 01:18AM

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

Patrick October 17, 2019 09:04PM

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

P.V.Anthony October 18, 2019 12:14AM

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

Patrick October 18, 2019 12:20AM

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

P.V.Anthony October 18, 2019 01:18AM

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

Patrick October 18, 2019 01:36AM

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

P.V.Anthony October 18, 2019 01:58AM

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

Patrick October 18, 2019 03:00AM

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

P.V.Anthony October 19, 2019 01:56AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 123
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready