apache rewrite规则中多RewriteCond条件 转换到nginx写法
最近在迁移写应用到nginx中,在rewrite上面遇到了些问题。
虽然大部分的rewrite规则转换到nginx中几乎改动很小,但是一些特殊的比如下面这段,在nginx里面可以说完全不一样。
1 2 3 4 5 | RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^.*(\.html|\.xml|\.css|\.js|\.gif|\.png|\.jpg|\.jpeg)$|.*(FCKeditor).*$|.*(fckeditor).*$|.*(userfiles).*|.*(testadow).|.*(api).*|.*(passportcode).* RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php |
转换到nginx的写法(只是参照的语法,并不是上面内容的转换)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | location /xxxx/ {
set $test "";
if ($request_method = POST) {
set $test P;
}
if ($http_cookie ~* "CCCC=.+(?:;|$)" ) {
set $test ${test}C";
}
if ($test = PC) {
#rewrite rule goes here.
}
} |