Nginx重定向循环
问题描述:
下面是我对nginx的配置。Nginx重定向循环
location/{
try_files $uri $uri/ $uri.html $uri.php?$query_string;
# Remove trailing slash
rewrite ^/(.*)/$ /$1 permanent;
rewrite /authors/(.*) /authors/search.php?author=$1;
}
我遇到的问题是,当我去www.mywebsite.com/authors时,会导致无限重定向。我想要的是www.mywebsite.com/authors载入www.mywebsite/authors/index.php和www.mywebsite.com/authors/EVERYOTHERSTRING进行最后的重写。我如何通过重写来实现这一点?
编辑:并仍然删除尾部斜线。
答
尝试改变这些重写规则...
rewrite ^/(.*)/$ /$1 permanent;
rewrite /authors/(.*) /authors/search.php?author=$1;
到...
rewrite ^/authors/(.*) /authors/search.php?author=$1 last;
rewrite ^/(.+)/$ /$1 permanent;
'/authors/search.php笔者= $ 1;''匹配/authors/(.* )'。所以它无限地重写 – zerkms 2014-09-25 05:09:14
不,问题不是那么单独。我将'/authors/search.php?author = $ 1;'改成了'/authorsTEMP/search.php?author = $ 1;'并且错误仍然发生。它与尾部斜杠线有关,因为重新定向错误在我删除时会停止。 – user1106340 2014-09-25 05:24:39