nginx 下如何只把根目录下的 index.php 重写到 index.html?

2016-11-05 15:21:49 +08:00
 zhangchaoquan

nginx 下如何只把根目录下的 index.php 重写到 index.html ?

4027 次点击
所在节点    NGINX
7 条回复
rrfeng
2016-11-05 15:37:55 +08:00
location = /index.php {
rewrite ....
或者 alias ...../index.html;
}
zhangchaoquan
2016-11-05 16:21:41 +08:00
试了
location = /index\.php {
rewrite index\.php /index.html break;
}

location ~ /index\.php {
rewrite index\.php /index.html break;
}

都不行,能说具体点吗?谢了
zhangchaoquan
2016-11-05 16:21:54 +08:00
@rrfeng 试了
location = /index\.php {
rewrite index\.php /index.html break;
}

location ~ /index\.php {
rewrite index\.php /index.html break;
}

都不行,能说具体点吗?谢了
kiwi95
2016-11-05 16:35:38 +08:00
删了 index.php 这个文件, 然后:

```
try_files $uri /index.html;
```
zhangchaoquan
2016-11-05 16:52:42 +08:00
@kiwi95 我试一下没有成功。这样写对吗?

location / {
try_files /index.php /index.html;
}

现在访问 index.php 是 file not found
Bardon
2016-11-05 17:28:04 +08:00
问个问题, index.php 接受参数传入吗?
否则,
rewrite ^/index.php$ /index.html redirect;
直接写到 server {} 内,不需要 location
zhangchaoquan
2016-11-05 17:34:36 +08:00
@Bardon 可以了,好人一生平安!

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

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

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

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

© 2021 V2EX