Why should I use question mark?

I want rewrite a uri to itself without querystring, I tried
rewrite .+ $uri permanent;
but it rewrite to the original uri, with querystring unstripped.

After googled, I try
rewrite .+ $uri? permanent;
and it works correctly.

But why?

Hello!

On Fri, Jul 06, 2012 at 10:44:15PM +0800, 任晓磊 wrote:

I want rewrite a uri to itself without querystring, I tried
rewrite .+ $uri permanent;
but it rewrite to the original uri, with querystring unstripped.

After googled, I try
rewrite .+ $uri? permanent;
and it works correctly.

But why?

Because it’s how it’s expected to work. By default the “rewrite”
directive preserves query string, and even if you write arguments
in a replacement string - they are added before original query
string which is still preserved. Trailing question mark is an
explicit flag that you don’t want to preserve query string.

http://nginx.org/r/rewrite

Maxim D.

On 2012-7-7, at 0:23, Maxim D. [email protected] wrote:

Hello!

Because it’s how it’s expected to work. By default the “rewrite”
directive preserves query string, and even if you write arguments
in a replacement string - they are added before original query
string which is still preserved. Trailing question mark is an
explicit flag that you don’t want to preserve query string.

Module ngx_http_rewrite_module

Thank you. I was too careless to look though the wiki.