rewritecond for nginx

Igor Sysoev is at rambler-co.ru
Fri Feb 27 14:52:35 MSK 2009


On Fri, Feb 27, 2009 at 03:44:51AM -0800, Chris Cortese wrote:

> I think I figured out the answer to my last question about perl CGI.  I 
> put the path to cgi-bin in the fastcgi_params file.
> 
> I have another question:
> 
> How can I tell nginx to not rewrite certain directories?  I use the 
> RewriteCond in Apache.  I googled for the answer and I read that I 
> should use "if" conditions.  But I'm still not totally clear.  I'm using 
> rewrite on most of my php code with:
> 
> 
>    if (!-e $request_filename) {
>      rewrite ^/(.*)$ /index.php?q=$1 last;
>    }
> 
> ...and that works fine..   now I just want to say:  Don't do any rewrite 
> for directories named /tmp, /filestore, and /cgi-bin.
> 
> I tried the following, thinking that the rewrite rule would accomplish 
> nothing other than telling nginx not to use any subsequent rewrite 
> rules.  It looks crazy but it's all I could come up with:
> 
> if ($request_filename ~ (tmp|filestore|cgi-bin)) {
>    rewrite ~/(.*)$ /$1 last;
>  }
> 
> I put those 3 lines before the other 3 lines up above.
> 
> What should I have instead?

You should forget to think in inverted RewriteCond/RewriteRule terms
and start to think in human natural locations:

     location / {
         ...
         error_page  404  = /index.php?q=$request_uri;
     }

     location /filestore/ {
         ...
     }

     location /tmp/ {
         ...
     }

     location /cgi-bin/ {
         ...
     }


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list