Назад | Перейти на главную страницу

Попытка переписать / directory / dir_variable / в /directory/dir_variable/index.php

Пытаюсь переписать примерно так:

domain.tld / staging / base_1 / в domain.tld / staging / base_1 / index.php, где «1» - это номер переменной.

но у меня цикл переадресации.

*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 ....

Вот директива местоположения, которую я использую, я читал документы, и похоже, что это сработает, но мне явно чего-то не хватает.

location ~* /staging/(.*) {
    rewrite ^/staging/(.*)$ /staging/$1/index.php last;
}

Попробуйте что-нибудь вроде:

location ~* /staging/(.*) {
    rewrite ^/staging/(.*)/$ /staging/$1/index.php break;
}

или ограничиться одним уровнем:

location ~* /staging/(*) {
    rewrite ^/staging/([^/]*)/$ /staging/$1/index.php break;
}

Возможно, вам нужно перечитать документ, как это объясняется здесь:

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 отметьте это как внутреннее перенаправление на nginx. Я предполагаю, что вы объявили location ~ \.php$ блокировать после этот, чтобы обрабатывать файлы php, но он не будет выбран в процессе выбора местоположения, потому что первое подходящее регулярное выражение побеждает. Таким образом, он рекурсивно входит в предыдущий блок местоположения.