0

我是 nginx 的新手,我正在尝试将 nginx 配置为使用 url 中第一个目录的名称将深层目录重写为 php。例如:

http://domain.com/news/search/band/ -> news.php
http://domain.com/article/blue/300/?arg=10 -> article.php?arg=10
http://domain.com/xxx/yyy/zzz/ -> xxx.php

我尝试了一些正则表达式和:

try_files $uri $uri/ @extensionless-php /index.php?$args =404;

但我没有成功;有人可以帮助我吗?谢谢

4

1 回答 1

0

回复我自己:

很多 apache 安装都启用了多视图。您可以再次使用 try_files 指令执行此操作:

location ~ ^(/.+)/ {
    try_files $uri $1?$args $1.php?$args;
}

尽管它并不完全像 Apache 中的 Multiviews 那样做(比如可以省略文件扩展名),但在 PHP 配置中,十分之九的情况需要上述行为,让 PHP 文件处理包含文件名的所有请求并附加了一些斜线。

于 2014-06-29T11:45:09.263 回答