我试图重写这样的东西:
domain.tld / staging / base_1 /到domain.tld / staging / base_1 / index.php其中'1'是一个可变数字。
但是得到一个redirect周期。
*1 rewrite or internal redirection cycle while processing "/staging/base_1//index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php ....
这里是我正在使用的位置指令,我已经阅读了文档,这似乎是可行的,但我显然缺less一些东西。
location ~* /staging/(.*) { rewrite ^/staging/(.*)$ /staging/$1/index.php last; }
也许你需要重新阅读文档,因为它在这里解释:
Syntax: rewrite regex replacement [flag]; Default: — Context: server, location, if[…]
An optional flag parameter can be one of: last stops processing the current set of ngx_http_rewrite_module directives and starts a search for a new location matching the changed URI; break stops processing the current set of ngx_http_rewrite_module directives as with the break directive; redirect returns a temporary redirect with the 302 code; used if a replacement string does not start with “http://” or “https://”; permanent returns a permanent redirect with the 301 code.
所以当你使用last标志时,就像内部redirect到nginx。 我猜你在这个之后声明了一个location ~ \.php$块,以便处理php文件,但是它不会在位置选举过程中被选中,因为第一个匹配的正则expression式会胜出。 因此它recursion地进入前一个位置块。
尝试像这样:
location ~* /staging/(.*) { rewrite ^/staging/(.*)/$ /staging/$1/index.php break; }
或限制到一个级别:
location ~* /staging/(*) { rewrite ^/staging/([^/]*)/$ /staging/$1/index.php break; }