Multipule Map modules

António P. P. Almeida appa at perusio.net
Mon Nov 7 22:07:17 UTC 2011


On 7 Nov 2011 20h54 WET, nginx-forum at nginx.us 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

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



More information about the nginx mailing list