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永久重定向 地址欄會顯示跳轉後的地址