rewrite 导致 nginx 一直重定向301 的问题分析

  • 出现问题的正则: rewrite ^/(.+)/index.html /$1/ permanent;

关键词: permanent,$1

$1表示路径中正则表达式匹配的第一个参数。
permanent 是 永久性重定向。请求日志中的状态码为301
第一个请求匹配到这条正则 返回 301 和 一个 新的URL ,这个 新的 url 和 旧的 url 一样, 所以出现无限重定向
就是 访问 http://www.xx.com/sj/ --> 返回 http://www.xx.com/sj/  继续访问  http://www.xx.com/sj/ --> 返回 http://www.xx.com/sj/ ........