nginx让根目录url自动跳转到rootpath/index.html,如何强制跳转到index.html?

问这个问题,一般给的都是这个几个问题的答案
1、nginx服务器怎样去掉url中的index.php
2、nginx服务器URL无法自动添加index.php
3、nginx如何隐藏index.php 或者.php 路径

我现在想要实现的目的是,访问目录强制301到 目录/index.html 或者 path/index.php,
但是:其它资源路径完全不变
比如:

  1. https://www.zhoulujun.cn/zhou...
  2. https://www.zhoulujun.cn/zhou...
  3. https://www.zhoulujun.cn/zhou...
  4. 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;
    }

}
    
    

结果均不能实现。
,跪拜解答,谢谢

回复
阅读 11.6k
1 个回答
location /zhoulujun {
    rewrite ^/(.*)$ http://www.zhoulujun.cn/zhoulujun/index.php permanent;
}

location / {
    ...
}

你是要这个效果吗?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏