當正確輸入網站 URL 時,例如:https://example.amsterdam
它應該立即將 URL 更改為:https://example.amsterdam/dist/index.php
我已經嘗試通過創建一個DirectoryIndex dist/index.php唯一的線索來解決這個問題,嘗試像這樣修復它是它只加載頁面而不是 URL 中的正確路徑。因此,當檔案打開并單擊按鈕時,
HREF不再起作用,因為路徑不正確。
所以我基本上想在URL中的正確路徑中打開檔案。當用戶輸入 URL 時立即
我現在的.htaccess
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

uj5u.com熱心網友回復:
這聽起來確實像一個XY 問題,因為“重定向”到DirectoryIndex檔案通常是不可取的,而且聽起來您正在補償其他問題。例如。在鏈接(以及靜態資產)中使用相對 URL 路徑,在/dist/應該隱藏子目錄時公開子目錄等。
無論如何,要回答您的具體問題...
我已經嘗試通過創建一個
DirectoryIndex dist/index.php
如果您特別想重定向請求(而不是內部子請求),那么您可以DirectoryIndexRedirect on在DirectoryIndex指令之外進行設定。換句話說:
DirectoryIndex dist/index.php
DirectoryIndexRedirect on
以上將觸發 302(臨時)重定向。您可以使用 http 狀態代碼301進行永久重定向。有關其他選項,請參閱檔案。
請注意,該DirectoryIndex指令適用于您請求的任何目錄。因此,如果您要請求,/dist/則上述指令將導致 mod_dir 查找/dist/dist/index.php(因為您已指定相對路徑)。DirectoryIndex /dist/index.php無論是否請求子目錄,您都可以使用(根相對路徑)始終提供相同的檔案。
或者,僅重定向檔案根目錄,然后使用 mod_rewrite。例如:
RewriteRule ^$ /dist/index.php [R,L]
同樣,以上是 302(臨時)重定向。用于R=301永久重定向。
盡管您不需要index.php出現在(可見的)URL 中,但只需將根重定向到/dist/并讓標準DirectoryIndex完成作業。例如:
DirectoryIndex index.php
RewriteRule ^$ /dist/ [R,L]
參考:
- https://httpd.apache.org/docs/2.4/mod/mod_dir.html#directoryindexredirect
- https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewriterule
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/511820.html
上一篇:未收到Firebase動態鏈接
