这个问题常见于以单入口文件为架构的 php 框架
修改 nginx 相应位置的配置为:
location / {
root /usr/share/nginx/html/xxx;
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php$1 last;
}
}
- xxx 是网站的根目录。
- 该配置重写了规则,将网站后的路径(例如:
https://www.icy2003.com/a/b
指的就是a/b
)重新指向了 index.php 并且把参数附加到后面。 - 对于配置了路由美化的一些 php 框架,这个配置还能用来隐藏 index.php。