# Multipule Map modules

**URL:** <https://www.ruby-forum.com/t/multipule-map-modules/213639>\
**Category:** NGINX\
**Created:** [November 7, 2011, 9:55pm UTC](https://www.ruby-forum.com/t/multipule-map-modules/213639 "2011-11-07T21:55:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [November 7, 2011, 9:55pm UTC](https://www.ruby-forum.com/t/multipule-map-modules/213639/1 "2011-11-07T21:55:16Z")

</div>

What i would like to do is like Apache is to use multiple map files and  
get the vars form them

i have tried the following and can only get one value `$variable1`  
what is a rewrite to get `$variable1` and `$variable2` in one rewrite

rewrite ^(^/_)/(._)$ /index.php?key1=$variable1&key2=$variable2 last;

map $uri $variable1 {  
default 11;  
/sub 7;

}  
map $uri $variable2 {  
default 78;  
/pep 23;  
}

Regards, David

Posted at Nginx Forum:

> **[Multipule Map modules](https://forum.nginx.org/read.php?2,217936,217936#msg-217936)**
>
> What i would like to do is like Apache is to use multiple map files and get the vars form them i have tried the following and can only get one value \`$variable1\` what is a rewrite to get \`$variable1\` and \`$variable2\` in one rewrite rewrite...

---

<div class="post-metadata">

**Author:** ![token](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e0b2c6/32.png) [@token](https://www.ruby-forum.com/u/token)\
**Post date:** [November 7, 2011, 11:08pm UTC](https://www.ruby-forum.com/t/multipule-map-modules/213639/2 "2011-11-07T23:08:16Z")

</div>

On 7 Nov 2011 20h54 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What i would like to do is like Apache is to use multiple map files  
> and get the vars form them
> 
> i have tried the following and can only get one value `$variable1`  
> what is a rewrite to get `$variable1` and `$variable2` in one  
> rewrite
> 
> rewrite ^(^/_)/(._)$ /index.php?key1=$variable1&key2=$variable2  
> last;

What are you trying to accomplish?

> map $uri $variable1 {  
> default 11;  
> /sub 7;

If your URI is /sub $variable1 becomes 7.

> }  
> map $uri $variable2 {  
> default 78;  
> /pep 23;  
> }

If your URI is /sub $variable2 becomes 23.

It works as it should. I don’t see any issue. Also your rewrite is  
unnecessary. Try this:

return 301 /index.php?key1=$variable1&key2=$variable2;

Do you mean that the request URI can contain both /pep and /sub?Like  
this:

[http://example.com/sub/pep/other-stuff-if-any](http://example.com/sub/pep/other-stuff-if-any)

If so then your matching must be done with a regex:

map $uri $variable1 {  
default 11;  
~/sub 7;  
}

map $uri $variable2 {  
default 78;  
~/pep 23;  
}

— appa

---

<div class="post-metadata">

**Author:** ![token](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e0b2c6/32.png) [@token](https://www.ruby-forum.com/u/token)\
**Post date:** [November 7, 2011, 11:13pm UTC](https://www.ruby-forum.com/t/multipule-map-modules/213639/3 "2011-11-07T23:13:13Z")

</div>

On Mon, Nov 07, 2011 at 03:54:24PM -0500, token wrote:

Hi there,

> What i would like to do is like Apache is to use multiple map files and  
> get the vars form them
> 
> i have tried the following and can only get one value `$variable1`  
> what is a rewrite to get `$variable1` and `$variable2` in one rewrite
> 
> rewrite ^(^/_)/(._)$ /index.php?key1=$variable1&key2=$variable2 last;

I confess I’m not sure exactly what it is you are trying to do.

For certain urls, grab parts of the url and send them as-is within  
QUERY\_STRING to a php-processor? (In which case: doing the grabbing in  
the location definition is probably easiest.)

Or grab parts of the url, and set other values in QUERY\_STRING based  
on the url parts? (In which case, matching on $uri at server level and  
using the map-ped value within the location block is probably easiest.)

Or maybe something else?

> map $uri $variable1 {  
> default 11;  
> /sub 7;
> 
> }  
> map $uri $variable2 {  
> default 78;  
> /pep 23;  
> }

The map documentation is at [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpMapModule#map)  
and there’s an example of if/set/map in the thread at  
[http://forum.nginx.org/read.php?2,194480](http://forum.nginx.org/read.php?2,194480)

And there are examples of php-without-rewrite around as well – in the  
location block, set “fastcgi\_param SCRIPT\_FILENAME” explicitly, as well  
as fastcgi\_pass.

Good luck,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![token](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e0b2c6/32.png) [@token](https://www.ruby-forum.com/u/token)\
**Post date:** [November 8, 2011, 6:21am UTC](https://www.ruby-forum.com/t/multipule-map-modules/213639/4 "2011-11-08T06:21:06Z")

</div>

Hi, António that is exactly wath is was trying to accomplish id didn’t  
know i had to use the “~” at the beginning of the map key.  
Thank you

> Do you mean that the request URI can contain both /pep and /sub?Like  
> this:

> [http://example.com/sub/pep/other-stuff-if-any](http://example.com/sub/pep/other-stuff-if-any)

> If so then your matching must be done with a regex:

> map $uri $variable1 {  
> default 11;  
> ~/sub 7;  
> }

> map $uri $variable2 {  
> default 78;  
> ~/pep 23;  
> }

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,217936,217959#msg-217959](http://forum.nginx.org/read.php?2,217936,217959#msg-217959)
