【发布时间】:2019-02-09 07:30:52
【问题描述】:
在 Apache 中,可以使用 .htaccess 将所有内容重定向到最近的 index.php
示例文件夹结构:
/Subdir
/index.php
/.htaccess
/Subdir
/Subdir/.htaccess
/Subdir/index.php
如果我访问/something,它将重定向到根index.php,如果我访问/Subdir/something,它将重定向到Subdir/index.php
这也可以在 nginx 中完成吗?
这应该是可能的,因为在 nginx 文档中它说If you need .htaccess, you’re probably doing it wrong :)
我知道如何将所有内容重定向到根 index.php:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
但是如何检查每个父目录中的 index.php 直到 / ?
编辑:
我发现这些规则做我想做的事:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /Subdir{
try_files $uri $uri/ /Subdir/index.php?$query_string;
}
但是有没有办法让它抽象,比如
location /$anyfolder{
try_files $uri $uri/ /$anyfolder/index.php?$query_string;
}
?
【问题讨论】:
标签: apache .htaccess nginx url-rewriting