问这个问题,一般给的都是这个几个问题的答案
1、nginx服务器怎样去掉url中的index.php
2、nginx服务器URL无法自动添加index.php
3、nginx如何隐藏index.php 或者.php 路径
我现在想要实现的目的是,访问目录强制301到 目录/index.html 或者 path/index.php,
但是:其它资源路径完全不变
比如:
- https://www.zhoulujun.cn/zhou...
- https://www.zhoulujun.cn/zhou...
- https://www.zhoulujun.cn/zhou...
- https://www.zhoulujun.cn/zhou...
4个路径实际内容都是一样的。我只想保留一个路径,最好是:https://www.zhoulujun.cn/zhou...
实现步骤:
A:如何让 让用户 访问1或者2的情况下,自动跳转到3?
起初用的办法:
location /zhoulujun {
rewrite ^/$ http://www.zhoulujun.cn/zhoulujun/index.php permanent;
}
但是,发现,该路径下,其它资源文件有问题
B:然后,放过来实施,3跳转到1或者2。
location zhoulujun/index.(html|php) {
rewrite https://www.zhoulujun.cn/zhoulujun/$is_args$args permanent;
}
但是,实测结果是,不停301,然后浏览器停止刷新,加载失败。
百度,谷歌的答案都是,
location / {
try_files $uri $uri /index.php;
}
谷歌的答案下面的多一些
location / {
if ( !-e $request_filename ) {
proxy_pass http://index;
}
}
结果均不能实现。
,跪拜解答,谢谢
你是要这个效果吗?