求一段 Nginx 配置,作用是在 URL 中隐藏 PHP 的后缀名。

2016 年 7 月 30 日
 terax

Google 之后知道是用 rewrite 规则来写,但是试了几个网上提供的写法都没效果。 于是来求助万能的 V2EXer ,万分感谢🙏

10639 次点击
所在节点    NGINX
8 条回复
aprikyblue
2016 年 7 月 30 日
首先你得让程序输出的 url 不带后缀。。。这不是 rewrite 管的。。
做完上边的然后才是 rewrite 的事
terax
2016 年 7 月 30 日
@aprikyblue 我在本机测试的时候用的是 Apache 作为服务器,就是可以直接不带后缀访问的。不太懂“程序输出的 url ”是什么意思哎?
babytomas
2016 年 7 月 30 日
让网站通过 /example 可以访问到索引目录下的 example.php ,例子:

```
rewrite ^/example$ /./example.php last;
```
yaodong
2016 年 7 月 30 日
目测楼主在 apache 用的是古老的连 html response 里面的 url 都 rewrite 的 mod 。这个好多年没见过了。
terax
2016 年 7 月 30 日
@yaodong 是 mac 自带的😳
chaegumi
2016 年 7 月 30 日
#if (!-e $request_filename){
# rewrite (.*) /index.php last;
#}
try_files $uri $uri/ /index.php?$query_string;
15759943015
2016 年 7 月 31 日
难道不是在说伪静态吗....把 php 后缀变成 html 后缀不是同理?
qinxi
2016 年 7 月 31 日
1 楼详细点就是
1,你的页面显示的 xxx.php 后面的.php 需要先去掉,
2,到服务端需要把 xxx 的 url rewrite 到 xxx.php

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/295954

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX