Nginx rewrite 的 last 以及 break 的区别

 

last:rewrite匹配后,会再次发起一个请求,只会对location里的规则再次匹配。

break:rewrite匹配后,不会发起请求,也不会匹配后面的规则。

 

举例:

location / {

root html;

index index.php index.html index.htm;

}

if ($request_uri ~* /cms/) {

rewrite "^/cms/(.*)\.php" /cms/index.php break;

# 这里使用last也可以,单独的if只处理一次

# "if"和"("需要空格

}

 

 

location / {

root html;

index index.php index.html index.htm;

if ($request_uri ~* /cms/) {

rewrite "^/cms/(.*)\.php" /cms/index.php break;

# 这里使用last会造成死循环,在location里的if会处理多次

}

 

需要注意url有问号的情况

比较不加"?"和加上"?"标记的URL跳转区别

rewrite ^/test(.*)$ http://www.yourdomain.com/home permanent;

访问http://www.yourdomain.com/test?id=5经过301跳转后的URL是

http://www.yourdomain.com/home?id=5

  

rewrite ^/test(.*)$ http://yourdomain.com/home? permanent;

访问http://www.yourdomain.com/test?id=5经过301跳转后的URL是

http://www.yourdomain.com/home

 

转载于: http://liuping0906.blog.51cto.com/2516248/1301125

转载于:https://www.cnblogs.com/ZHshuang463508120/p/4772548.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值