# Using map module variable being unset with if

**URL:** <https://www.ruby-forum.com/t/using-map-module-variable-being-unset-with-if/208593>\
**Category:** NGINX\
**Created:** [June 22, 2011, 7:06am UTC](https://www.ruby-forum.com/t/using-map-module-variable-being-unset-with-if/208593 "2011-06-22T07:06:59Z")\
**Posts on this page:** 6\
**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:** [June 22, 2011, 7:06am UTC](https://www.ruby-forum.com/t/using-map-module-variable-being-unset-with-if/208593/1 "2011-06-22T07:06:59Z")

</div>

Hey guys,

I have been trying to use the nginx map module to do some rewrites in  
bulk, basically my  
map looks something like this:

map $request\_body $var {  
default no;  
~.+.string1 dorw;  
~.+.string2 dorw;  
…  
}

in a location i have the following

if ($var = dorw){  
rewrite ^ /home last;  
}

I also have a log\_format which logs the variable state (and it reports  
correct), however  
once I enable that if… the $var seems to reset to ‘no’.

Any ideas? This is kind of confusing.

Thanks and any help is much appreciated.

Lou

Posted at Nginx Forum:

> **[Using map module variable being unset with if](https://forum.nginx.org/read.php?2,208914,208914#msg-208914)**
>
> Hey guys, I have been trying to use the nginx map module to do some rewrites in bulk, basically my map looks something like this: map $request\_body $var { default no; ~.+.string1 dorw; ~.+.string2 dorw; ... }

---

<div class="post-metadata">

**Author:** ![kamlou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecccb3/32.png) [@kamlou](https://www.ruby-forum.com/u/kamlou)\
**Post date:** [June 22, 2011, 10:48am UTC](https://www.ruby-forum.com/t/using-map-module-variable-being-unset-with-if/208593/2 "2011-06-22T10:48:45Z")

</div>

Hello!

On Wed, Jun 22, 2011 at 01:06:20AM -0400, kamlou wrote:

> …  
> once I enable that if.. the $var seems to reset to ‘no’.
> 
> Any ideas? This is kind of confusing.

$request\_body isn’t available unless it’s read, and this happens  
after rewrite phase where “if” is executed. Therefore testing  
$var with “if” will always result in “no” and this result will be  
cached for further use.

Maxim D.

---

<div class="post-metadata">

**Author:** ![kamlou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecccb3/32.png) [@kamlou](https://www.ruby-forum.com/u/kamlou)\
**Post date:** [June 22, 2011, 4:36pm UTC](https://www.ruby-forum.com/t/using-map-module-variable-being-unset-with-if/208593/3 "2011-06-22T16:36:24Z")

</div>

Thanks Maxim.

Any other way I can accomplish this using the map above? Thanks

Posted at Nginx Forum:

> **[Re: Using map module variable being unset with if](https://forum.nginx.org/read.php?2,208914,209084#msg-209084)**
>
> Hey guys, I have been trying to use the nginx map module to do some rewrites in bulk, basically my map looks something like this: map $request\_body $var { default no; ~.+.string1 dorw; ~.+.string2 dorw; ... }

---

<div class="post-metadata">

**Author:** ![kamlou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecccb3/32.png) [@kamlou](https://www.ruby-forum.com/u/kamlou)\
**Post date:** [June 22, 2011, 4:52pm UTC](https://www.ruby-forum.com/t/using-map-module-variable-being-unset-with-if/208593/4 "2011-06-22T16:52:28Z")

</div>

Also, is there any variable in Nginx that will hold the original URL  
(including anchors, like /foo/bar/#get/this/that)?

Thanks

Posted at Nginx Forum:

> **[Re: Using map module variable being unset with if](https://forum.nginx.org/read.php?2,208914,209088#msg-209088)**
>
> Hey guys, I have been trying to use the nginx map module to do some rewrites in bulk, basically my map looks something like this: map $request\_body $var { default no; ~.+.string1 dorw; ~.+.string2 dorw; ... }

---

<div class="post-metadata">

**Author:** ![kamlou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecccb3/32.png) [@kamlou](https://www.ruby-forum.com/u/kamlou)\
**Post date:** [June 23, 2011, 5:34am UTC](https://www.ruby-forum.com/t/using-map-module-variable-being-unset-with-if/208593/5 "2011-06-23T05:34:14Z")

</div>

2011/6/22 kamlou [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Also, is there any variable in Nginx that will hold the original URL  
> (including anchors, like /foo/bar/#get/this/that)?

Browsers do not send anchors (fragments) in their requests to the  
server.

---

<div class="post-metadata">

**Author:** ![kamlou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecccb3/32.png) [@kamlou](https://www.ruby-forum.com/u/kamlou)\
**Post date:** [June 22, 2011, 4:56pm UTC](https://www.ruby-forum.com/t/using-map-module-variable-being-unset-with-if/208593/6 "2011-06-22T16:56:47Z")

</div>

On 22 Jun 2011 15h51 WEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Also, is there any variable in Nginx that will hold the original URL  
> (including anchors, like /foo/bar/#get/this/that)?

Without args: [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpCoreModule#.24uri)  
With args: [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpCoreModule#.24request_uri)

— appa
