Nginx与Apache的Rewrite规则的区别{转}
一、Nginx Rewrite规则相关指令
Nginx Rewrite规则相关指令有if、rewrite、set、return、break等,其中rewrite是最关键的指令。一个简单的Nginx Rewrite规则语法如下:
rewrite ^/b/(.*)\.html /play.php?video=$1 break;
if (!-f $request_filename) { rewrite ^/img/(.*)$ /site/$host/images/$1 last; }
RewriteRule ^/(mianshi|xianjing)/$ /zl/index.php?name=$1 [L]RewriteRule ^/ceshi/$ /zl/ceshi.php [L]RewriteRule ^/(mianshi)_([a-zA-Z]+)/$ /zl/index.php?name=$1_$2 [L]RewriteRule ^/pingce([0-9]*)/$ /zl/pingce.php?id=$1 [L]
rewrite ^/(mianshi|xianjing)/$ /zl/index.php?name=$1 last;rewrite ^/ceshi/$ /zl/ceshi.php last;rewrite ^/(mianshi)_([a-zA-Z]+)/$ /zl/index.php?name=$1_$2 last;rewrite ^/pingce([0-9]*)/$ /zl/pingce.php?id=$1 last;
rewrite ^/([0-9]{5}).html$ /x.jsp?id=$1 last;
rewrite “^/([0-9]{5}).html$” /x.jsp?id=$1 last;
RewriteRule ^/html/tagindex/([a-zA-Z]+)/.*$ /$1/ [R=301,L]
rewrite ^/html/tagindex/([a-zA-Z]+)/.*$ http://$host/$1/ permanent;
RewriteRule ^/user/login/$ /user/login.php?login=1&forward=http://%{HTTP_HOST} [L]
rewrite ^/user/login/$ /user/login.php?login=1&forward=http://$host last;
RewriteCond %{HTTP_HOST} ^(.*?)\.domain\.com$RewriteCond %{HTTP_HOST} !^qita\.domain\.com$RewriteCond %{DOCUMENT_ROOT}/market/%1/index.htm -fRewriteRule ^/wu/$ /market/%1/index.htm [L]
if ($host ~* ^(.*?)\.domain\.com$) { set $var_wupin_city $1; set $var_wupin ‘1′; } if ($host ~* ^qita\.domain\.com$) { set $var_wupin ‘0′; } if (!-f $document_root/market/$var_wupin_city/index.htm) { set $var_wupin ‘0′; } if ($var_wupin ~ ‘1′) { rewrite ^/wu/$ /market/$var_wupin_city/index.htm last; }