我在 Next.js 應用程式中遇到重定向問題。
我做了靜態匯出(next build && next export)。
應用程式的主機位于子目錄(https://www.myhost.com/subdirectory/**[index.html here]**)中,所以我basePath: '/subdirectory'在next.config.js. 一見鐘情,一切都恰到好處。
在應用程式內重定向作業正常。但是當用戶重繪 另一個頁面上的頁面然后索引 - 假設頁面被命名為子頁面(https://www.myhost.com/subdirectory/subpage)該站點不會將用戶重定向到子頁面而是轉到https ://www.myhost.com/(甚至不是專案所在的子目錄)。
我非常感謝有人的幫助。
這里是.htaccess檔案。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html/ [L]
</IfModule>
如果你需要任何其他檔案,如果你發表評論,我可以編輯這篇文章。
提前致謝!!
uj5u.com熱心網友回復:
我假設您的.htaccess檔案位于/subdirectory/.htaccess. 這些指令的撰寫就像應用程式在檔案根目錄中一樣,而不是在子目錄中。
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule . /index.html/ [L] </IfModule>
最后一條RewriteRule指令將所有請求發送到檔案根目錄。你需要:
- 洗掉替換字串 (
/index.html/)上的斜杠前綴 - 并洗掉尾部斜杠。(通常這會導致 404,除非啟用了路徑資訊?)
RewriteBase完全洗掉指令。- 在
<IfModule>不需要包裝。
考慮到以上幾點,請嘗試以下操作:
# /subdirectory/.htaccess
RewriteEngine On
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . index.html [L]
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/316598.html
標籤:javascript .htaccess 重定向 下一个.js
下一篇:IIS重定向請求
