簡體   English   中英

Nextjs靜態導出重定向問題

[英]Nextjs static export redirecting issue

我在 Next.js 應用程序中遇到重定向問題。

我做了靜態導出( next build && next export )。

應用程序的主機位於子目錄( https://www.myhost.com/subdirectory/**[index.html here]**)中,所以我在next.config.js使用了basePath: '/subdirectory' 一見鍾情,一切都恰到好處。

在應用程序內重定向工作正常。 但是當用戶刷新另一個頁面上的頁面然后索引 - 假設頁面被命名為頁面( 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>

如果你需要任何其他文件,如果你發表評論,我可以編輯這篇文章。

提前致謝!!

我假設您的.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指令將所有請求發送到文檔根目錄。 你需要:

  1. 刪除替換字符串 ( /index.html/ ) 上的斜杠前綴
  2. 並刪除尾部斜杠。 (通常這會導致 404,除非啟用了路徑信息?)
  3. 完全刪除RewriteBase指令。
  4. <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]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM