Py学习  »  NGINX

nginx“try_files”中的cascade index.php

nice ass • 5 年前 • 490 次点击  

在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;
} 

?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/37983
 
490 次点击  
文章 [ 1 ]  |  最新文章 5 年前