Multiple conditions for rewrite

heya heya
does anybody know how I could user ngx rewrite to port the mod_rewrite
ability
to have multiple conditions ?
like:
RewriteCond cond1
RewriteCond cond2
RewriteRule xmoo bla

the current config I am using:
if (cond1 && cond2) {
}

does not work (also using &, and does not work)

and:
if (cond1) {
if (cond2) {
}
}

does not work either :frowning:

Should I use something like the “break”/“last” combinations ?

Perl regular expressions should work. Something similar to the
following where we see if the request method is GET or HEAD and deny
the rest.

Only allow GET and HEAD request methods

  if ($request_method !~ ^(GET|HEAD)$ ) {
     return 404;
  }

Hope this helps,

Nginx “how to” - Fast, Secure and Efficient Web Server
http://calomel.org/nginx.html


Calomel @ http://calomel.org
Open Source Research and Reference

Well, the problem is that I want to check two variables at a time.
Btw, congrats for calomel, one of my fav. openbsd resource :slight_smile:

On Wed, May 7, 2008 at 10:42 AM, Andrei GUDIU [email protected]
wrote:

}

Should I use something like the “break”/“last” combinations ?

You can’t nest if statements in nginx. Every time that I’ve needed
nested if statements I’ve been able to wrap it up in a separate
location block or something similar. Sometimes you have to think
about it for a little bit, but the solution usually presents itself.

You probably can leverage break/last to allow fall through in your
logic, but personally I always incorrectly guess the behavior the
first time I look at mroe complex rewrites. :slight_smile:

I’d love to see nested ifs in nginx but I am a little scared about how
people will use them.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs