0

我正在尝试模拟多视图,但 try_files 有问题。一切都好,但我想重写所有未管理到 /index.php 的 url(但没有 404):

location ~ ^(/.+)/ {
   try_files $uri $uri/ $1.php?$args @extensionless-php /index.php;
}
location @extensionless-php {
   rewrite ^(.*)/ $1.php;
}

所有 url 都被重写为 /index.php。如果我在第一个位置的末尾删除 /index.php,一切都很好,除了非托管 url(我想重写为索引)。任何想法?谢谢

4

1 回答 1

0

/index.php如您所说,您可以尝试从第一个位置删除。然后,为了让它重定向到/index.php找不到 php 文件时,你可以在location处理.php请求的地方添加几行:

location ~ \.php$ {
    if (!-f $request_filename) {
        rewrite    .*    /index.php;
    }
    # your other directives such as fastcgi_pass 127.0.0.1:9000; etc.
}
于 2014-06-29T12:42:15.360 回答