需求:訪問http://192.168.1.222:8099/ksdkfd/callback 其中ksdkfd是任意字符
跳轉到http://192.168.1.222:8099/api/paycb/ksdkfd
location ~* ^/.+/callback$ {
index index.html index.htm;
rewrite "^/(.+)/callback" "/api/paycb/$1" permanent;
}
break 和last的區別
location /break {
rewrite /break/(.*) /test/$1 break;
echo break page;
}
location /last {
rewrite /last/(.*) /test/$1 last;
echo last page;
}
location /test/ {
echo test page;
}
匹配到break之後,rewrite完成了。繼續執行下面的。
匹配到last之後,rewrite完成了。跳出location,重新匹配rewrite之後的url,也就是匹配到了/test/ ;
注意,要使用echo需要安裝nginx的echo模塊。