在Apache中,可以使用
.htaccess
文件夹结构示例:
/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
:)
我知道如何将所有内容重定向到root 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;
}
?