# Small bug in rewrite rules using if (ugh, yes, if is bad.)

**URL:** <https://www.ruby-forum.com/t/small-bug-in-rewrite-rules-using-if-ugh-yes-if-is-bad/211283>\
**Category:** NGINX\
**Created:** [August 31, 2011, 5:26pm UTC](https://www.ruby-forum.com/t/small-bug-in-rewrite-rules-using-if-ugh-yes-if-is-bad/211283 "2011-08-31T17:26:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [August 31, 2011, 5:26pm UTC](https://www.ruby-forum.com/t/small-bug-in-rewrite-rules-using-if-ugh-yes-if-is-bad/211283/1 "2011-08-31T17:26:43Z")

</div>

Hello folks,

Just thought I would report a small bug with rewrite interacting with  
if.

Here is my simple setup:

server {  
server\_name [example.dev.com](http://example.dev.com);  
location ^~ /salad/add {  
if ($arg\_paramThree = “foobar”) {  
rewrite ^  
[https://example.this.com?PARAM\_ONE=$arg\_paramOne&PARAM\_TWO=$arg\_paramTwo](https://example.this.com?PARAM_ONE=$arg_paramOne&PARAM_TWO=$arg_paramTwo)?  
redirect;  
}  
proxy\_pass http://127.0.0.1:8080$request\_uri;  
}  
}

So when I hit the server with this URL:

[http://example.dev.com/salad/add?paramThree=foobar&paramTwo=two&paramOne=one](http://example.dev.com/salad/add?paramThree=foobar&paramTwo=two&paramOne=one)

It is rewritten to be:

[https://example.this.com?PARAM\_ONE=one&PARAM\_TWO=two?paramThree=foobar](https://example.this.com?PARAM_ONE=one&PARAM_TWO=two?paramThree=foobar)

If I use the following if conditional, the behavior is as expected:

if ($args ~ “paramThree=foobar”) {

I tried to use OpenID for Nginx Trac, but am a little leary to do so  
because  
the server cert is not valid. So I am posting it here.

Thanks,  
-peter

---

<div class="post-metadata">

**Author:** ![Peter\_Portante](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f9ae1b/32.png) [@Peter\_Portante](https://www.ruby-forum.com/u/Peter_Portante)\
**Post date:** [August 31, 2011, 5:53pm UTC](https://www.ruby-forum.com/t/small-bug-in-rewrite-rules-using-if-ugh-yes-if-is-bad/211283/2 "2011-08-31T17:53:17Z")

</div>

Hello!

On Wed, Aug 31, 2011 at 11:26:29AM -0400, Peter Portante wrote:

> ```
> rewrite ^
> 
> ```
> 
> It is rewritten to be:
> 
> [https://example.this.com?PARAM\_ONE=one&PARAM\_TWO=two?paramThree=foobar](https://example.this.com?PARAM_ONE=one&PARAM_TWO=two?paramThree=foobar)
> 
> If I use the following if conditional, the behavior is as expected:
> 
> if ($args ~ “paramThree=foobar”) {

Works ok here. Which nginx version do you use?

Maxim D.

---

<div class="post-metadata">

**Author:** ![Peter\_Portante](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f9ae1b/32.png) [@Peter\_Portante](https://www.ruby-forum.com/u/Peter_Portante)\
**Post date:** [September 28, 2011, 3:31am UTC](https://www.ruby-forum.com/t/small-bug-in-rewrite-rules-using-if-ugh-yes-if-is-bad/211283/3 "2011-09-28T03:31:03Z")

</div>

On Wed, Aug 31, 2011 at 11:52 AM, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > server {  
> > }
> > 
> > If I use the following if conditional, the behavior is as expected:
> > 
> > if ($args ~ “paramThree=foobar”) {
> 
> Works ok here. Which nginx version do you use?

1.0.4

thanks for taking the time to check it out.

---

<div class="post-metadata">

**Author:** ![Peter\_Portante](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f9ae1b/32.png) [@Peter\_Portante](https://www.ruby-forum.com/u/Peter_Portante)\
**Post date:** [September 28, 2011, 10:26am UTC](https://www.ruby-forum.com/t/small-bug-in-rewrite-rules-using-if-ugh-yes-if-is-bad/211283/4 "2011-09-28T10:26:01Z")

</div>

Hello!

On Tue, Sep 27, 2011 at 09:30:40PM -0400, Peter Portante wrote:

> > > Here is my simple setup:  
> > > proxy\_pass http://127.0.0.1:8080$request\_uri;
> 
> 1.0.4
> 
> thanks for taking the time to check it out.

Could you please provide debug log? Please see  
[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/Debugging) for details.

Maxim D.
