Ruby Forum NGINX > Multiple conditions for rewrite

Posted by Andrei GUDIU (Guest)
on 07.05.2008 18:49
(Received via mailing list)
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 :(

Should I use something like the "break"/"last" combinations ?
Posted by Calomel (Guest)
on 07.05.2008 19:26
(Received via mailing list)
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
Posted by Andrei GUDIU (Guest)
on 08.05.2008 00:31
(Received via mailing list)
Well, the problem is that I want to check two variables at a time.
Btw, congrats for calomel, one of my fav. openbsd resource :)
Posted by Corey Donohoe (atmos)
on 08.05.2008 01:36
(Received via mailing list)
On Wed, May 7, 2008 at 10:42 AM, Andrei GUDIU <andreig@openbsd-box.org> 
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. :)

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