【发布时间】:2018-04-11 00:17:10
【问题描述】:
我正在开发新项目,该项目将有许多来自旧网站 uri 的重定向。许多旧的 uri 在 uri 中包含 .php 扩展名,Nginx 尝试将它们作为文件加载,而不是回退到我们的重定向控制器方法。
为了让它更复杂一点,我们使用带有文件管理器的所见即所得编辑器,当调用它时 - 使用 .php 扩展名,因此需要排除这个。
实际上,我希望它以这样的方式工作,这样当我调用旧的uri(例如/old-page/path/file.php)时,它将通过index.php 路由它,但是当我调用/vendor/ckfinder/plugins/filemanager/dialog.php?... 时,它将加载实际文件。
我看过这篇文章,它并没有真正解决我所追求的,但我认为这是一个很好的起点How to remove both .php and .html extensions from url using NGINX?
我现有的设置是
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
任何帮助将不胜感激。
更新
我尝试了@Richard Smith 的建议,在阅读了我认为应该可行的文档后,但不幸的是,无论出于何种原因 - 它没有 - 这是我尝试过的:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php?$query_string;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
include fastcgi_params;
}
所以try_files 检查$uri 是否存在——如果不存在,它会退回到/index.php?$query_string;,它应该将请求指向index.php。知道我在这里可能缺少什么吗?
【问题讨论】:
标签: php nginx server nginx-config