鍍金池/ 問答/Linux  網(wǎng)絡(luò)營銷/ nginx讓根目錄url自動跳轉(zhuǎn)到rootpath/index.html,如何強

nginx讓根目錄url自動跳轉(zhuǎn)到rootpath/index.html,如何強制跳轉(zhuǎn)到index.html?

問這個問題,一般給的都是這個幾個問題的答案
1、nginx服務(wù)器怎樣去掉url中的index.php
2、nginx服務(wù)器URL無法自動添加index.php
3、nginx如何隱藏index.php 或者.php 路徑

我現(xiàn)在想要實現(xiàn)的目的是,訪問目錄強制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個路徑實際內(nèi)容都是一樣的。我只想保留一個路徑,最好是:https://www.zhoulujun.cn/zhou...
實現(xiàn)步驟:
A:如何讓 讓用戶 訪問1或者2的情況下,自動跳轉(zhuǎn)到3?
起初用的辦法:
location /zhoulujun {

rewrite ^/$ http://www.zhoulujun.cn/zhoulujun/index.php permanent;

}
但是,發(fā)現(xiàn),該路徑下,其它資源文件有問題
B:然后,放過來實施,3跳轉(zhuǎn)到1或者2。
location zhoulujun/index.(html|php) {

    rewrite https://www.zhoulujun.cn/zhoulujun/$is_args$args permanent;
}

但是,實測結(jié)果是,不停301,然后瀏覽器停止刷新,加載失敗。

百度,谷歌的答案都是,
location / {

            try_files $uri $uri /index.php;
    }

谷歌的答案下面的多一些
location / {

    if ( !-e $request_filename ) {
      proxy_pass      http://index;
    }

}
    
    

結(jié)果均不能實現(xiàn)。
,跪拜解答,謝謝

回答
編輯回答
挽青絲
location /zhoulujun {
    rewrite ^/(.*)$ http://www.zhoulujun.cn/zhoulujun/index.php permanent;
}

location / {
    ...
}

你是要這個效果嗎?

2018年3月25日 09:15