rewrite ^/connect$ http://connect.myweb.com permanent; rewrite ^/connect/(.*)$ http://connect.myweb.com/$1 permanent;
if ($host = "connect.myweb.com"){ rewrite ^/(.*)$ http://www.myweb.com/connect/$1 permanent; }
if ($host != 'www.myweb.com' ) { rewrite ^/(.*)$ http://www.myweb.com/$1 permanent; }
rewrite "/category/(.*).html$" /category/?cd=$1 last;
if (!-e $request_filename){ rewrite ^/admin/(.*)$ /admin/index.php?s=/$1 last; }
if (!-e $request_filename){ rewrite ^/(.*)$ /index.php?s=/$1 last; }
rewrite ^/xinwen/([0-9]+)\.html$ /404.html last;
rewrite ^/news/radaier.html http://www.myweb.com/strategy/ permanent;
rewrite http://www.myweb.com/123/456.php /404.html last;
location ~//.ht { deny all; }
location ~ ^/data {
deny all;
}
location ~ /www/log/123.log { deny all; }
rewrite ^/news/activies/2014\-([0-9]+)\-([0-9]+)/(.*)$ http://www.myweb.com/news/activies/$3 permanent;
若是须要打开带有play的连接就跳转到play,不过/admin/play这个不能跳转php
if ($request_filename ~ (.*)/play){ set $payvar '1';} if ($request_filename ~ (.*)/admin){ set $payvar '0';} if ($payvar ~ '1'){ rewrite ^/ http://play.myweb.com/ break; }
if ($request_uri ~ "/\?gid\=6"){return http://www.myweb.com/123.html;}
正则表达式匹配,其中:html
* ~ 为区分大小写匹配nginx
* ~* 为不区分大小写匹配web
* !~和!~*分别为区分大小写不匹配及不区分大小写不匹配正则表达式
文件及目录匹配,其中:spa
* -f和!-f用来判断是否存在文件code
* -d和!-d用来判断是否存在目录htm
* -e和!-e用来判断是否存在文件或目录blog
* -x和!-x用来判断文件是否可执行it
flag标记有:
* last 至关于Apache里的[L]标记,表示完成rewrite
* break 终止匹配, 再也不匹配后面的规则
* redirect 返回302临时重定向 地址栏会显示跳转后的地址
* permanent 返回301永久重定向 地址栏会显示跳转后的地址