【发布时间】:2017-02-05 19:51:25
【问题描述】:
我在使用 FastCGI 启用的 NGINX 和 PHP7 中遇到 URL 重写问题。
要求如下。
原始网址: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;
}
}
任何人都可以帮助我解决这个问题或指向我可以获取更多信息的其他页面吗?
谢谢
【问题讨论】: