我在使用FastCGI启用的NGINX和PHP7中的URL重写中遇到了问题。禁用.php扩展名,但运行没有.php的文件作为php文件
要求如下。
原始地址:http://example.com/somename1.php
响应:它会抛出404错误
原始地址:http://example.com/somename1
响应:它将执行http://example.com/somename1.php
原始地址:http://example.com或http://example.com/
响应:它将执行http://example.com/index.php
我已经通过了以下网址,但他们不足以满足上述需求。
- How to remove both .php and .html extensions from url using NGINX?
- remove .php from url with rewrite rule
- remove .php extension from url in nginx
样本 “默认” 文件的内容如下。
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location/{
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
}
location ~ /\.ht {
deny all;
}
}
有没有人可以帮我解决这个问题,或者指点我一些其他的页面,我可以获得更多信息?
感谢
此答案不完整,对遇到同样问题的人没有帮助。应该在这里展示所有部分的完整答案,而不是简单地依赖未来可能无法使用的链接。换句话说,服务器模块在工作时是什么样的? – Tomas