S
S
Sergey Savostin2020-12-02 21:47:04
Nginx
Sergey Savostin, 2020-12-02 21:47:04

How to NOT forward $args in nginx rewrite?

Then I suddenly ran into a problem, what kind of rewrite is:
rewrite ^/([0-9]+)/$ /index.php?id=$1 last;
When requesting the form /1234/?id=4321
, it actually passes 4321 in $_REQUEST['id'] , not 1234.
Moreover, in such a rewrite

rewrite ^/some/([0-9]+)/$ /index.php?secret=abc&id=$1 last;

request /some/1234/?secret=bcd to secret is passed to bcd, which is not expected at all...

Can I somehow force Nginx to ignore (not pass below) $args in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-12-02
@savostin

nginx.org/ru/docs/http/ngx_http_rewrite_module.htm...

If the replacement string specifies new query arguments, then the previous query arguments are added after them. If this behavior is undesirable, you can opt out of this addition by ending the replacement string with a question mark

rewrite ^/([0-9]+)/$ /index.php?id=$1? last;
rewrite ^/some/([0-9]+)/$ /index.php?secret=abc&id=$1? last;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question