码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx rewrite 的 last 以及 break 的区别

时间:2015-08-31 11:49:12      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

 

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

Nginx rewrite 的 last 以及 break 的区别

标签:

原文地址:http://www.cnblogs.com/ZHshuang463508120/p/4772548.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!