# Rewriting uri as querystring using nginx?

**URL:** <https://www.ruby-forum.com/t/rewriting-uri-as-querystring-using-nginx/217172>\
**Category:** NGINX\
**Created:** [February 23, 2012, 6:45am UTC](https://www.ruby-forum.com/t/rewriting-uri-as-querystring-using-nginx/217172 "2012-02-23T06:45:56Z")\
**Posts on this page:** 3\
**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:** [February 23, 2012, 6:45am UTC](https://www.ruby-forum.com/t/rewriting-uri-as-querystring-using-nginx/217172/1 "2012-02-23T06:45:56Z")

</div>

How do I rewrite URIs of the form

[http://domain1/one/two?three=four](http://domain1/one/two?three=four)

to

[http://domain2?path=http%3A%2F%2Fdomain1%2Fone%2Ftwo%3Fthree%3Dfour](http://domain2?path=http%3A%2F%2Fdomain1%2Fone%2Ftwo%3Fthree%3Dfour)

using nginx?

Posted at Nginx Forum:

> **[Rewriting uri as querystring using nginx?](https://forum.nginx.org/read.php?2,222889,222889#msg-222889)**
>
> How do I rewrite URIs of the form http://domain1/one/two?three=four to http://domain2?path=http%3A%2F%2Fdomain1%2Fone%2Ftwo%3Fthree%3Dfour using nginx?

---

<div class="post-metadata">

**Author:** ![junius\_wang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/82dd89/32.png) [@junius\_wang](https://www.ruby-forum.com/u/junius_wang)\
**Post date:** [February 23, 2012, 8:11am UTC](https://www.ruby-forum.com/t/rewriting-uri-as-querystring-using-nginx/217172/2 "2012-02-23T08:11:26Z")

</div>

On 2012-02-23 12:45, junius wang wrote:

> How do I rewrite URIs of the form
> 
> [http://domain1/one/two?three=four](http://domain1/one/two?three=four)
> 
> to
> 
> [http://domain2?path=http%3A%2F%2Fdomain1%2Fone%2Ftwo%3Fthree%3Dfour](http://domain2?path=http%3A%2F%2Fdomain1%2Fone%2Ftwo%3Fthree%3Dfour)

Perhaps something like this:

rewrite ^ [http://domain2?path=http://domain1$request\_uri$is\_args$args](http://domain2?path=http://domain1$request_uri$is_args$args)  
permanent;

Not sure about the escapes though.

---

<div class="post-metadata">

**Author:** ![junius\_wang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/82dd89/32.png) [@junius\_wang](https://www.ruby-forum.com/u/junius_wang)\
**Post date:** [February 23, 2012, 5:02pm UTC](https://www.ruby-forum.com/t/rewriting-uri-as-querystring-using-nginx/217172/3 "2012-02-23T17:02:57Z")

</div>

On 23 Fev 2012 06h45 CET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How do I rewrite URIs of the form
> 
> [http://domain1/one/two?three=four](http://domain1/one/two?three=four)
> 
> to
> 
> [http://domain2?path=http%3A%2F%2Fdomain1%2Fone%2Ftwo%3Fthree%3Dfour](http://domain2?path=http%3A%2F%2Fdomain1%2Fone%2Ftwo%3Fthree%3Dfour)

To escape you need to do a capture.

rewrite ^(.\*)$ [http://domain2?path=$1](http://domain2?path=$1);

— appa
