# Why should I use question mark?

**URL:** <https://www.ruby-forum.com/t/why-should-i-use-question-mark/221276>\
**Category:** NGINX\
**Created:** [July 6, 2012, 4:45pm UTC](https://www.ruby-forum.com/t/why-should-i-use-question-mark/221276 "2012-07-06T16:45:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [July 6, 2012, 4:45pm UTC](https://www.ruby-forum.com/t/why-should-i-use-question-mark/221276/1 "2012-07-06T16:45:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![SSSSSSSSSS\_SS\_SSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@SSSSSSSSSS\_SS\_SSS](https://www.ruby-forum.com/u/SSSSSSSSSS_SS_SSS)\
**Post date:** [July 6, 2012, 6:23pm UTC](https://www.ruby-forum.com/t/why-should-i-use-question-mark/221276/2 "2012-07-06T18:23:20Z")

</div>

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.

> **[Module ngx\_http\_rewrite\_module](http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite)**
>
> The ngx\_http\_rewrite\_module module is used to change request URI using PCRE regular expressions, return redirects, and conditionally select configurations.

Maxim D.

---

<div class="post-metadata">

**Author:** ![SSSSSSSSSS\_SS\_SSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@SSSSSSSSSS\_SS\_SSS](https://www.ruby-forum.com/u/SSSSSSSSSS_SS_SSS)\
**Post date:** [July 7, 2012, 2:40am UTC](https://www.ruby-forum.com/t/why-should-i-use-question-mark/221276/3 "2012-07-07T02:40:31Z")

</div>

On 2012-7-7, at 0:23, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](http://nginx.org/r/rewrite)

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