簡體   English   中英

使用htaccess將所有請求重定向到主頁(在URL中隱藏index.html)

[英]Redirect all requests to main page using htaccess (hide index.html in URL)

我想將所有請求重定向到主頁(index.html)。 狀態欄中的網址不應顯示index.html。 目前,我正在使用以下代碼,該代碼重定向到index.html並將其顯示在URL中:

RewriteEngine on RewriteCond %{REQUEST_URI} !^/index.html$ RewriteCond %{REQUEST_URI} !.(gif|jpeg|png|css|js)$ RewriteRule .* /index.html [L,R=302]

我應該進行哪些更改以使其按預期工作? 謝謝!

嘗試:

RewriteEngine on 
RewriteCond %{REQUEST_URI} !^/(index.html)?$ 
RewriteCond %{REQUEST_URI} !.(gif|jpeg|png|css|js)$ 
RewriteRule .* / [L,R=302]

如果它按預期工作,除了瀏覽器的外部重定向外,您只需要刪除R = 302標志,該標志告訴服務器發送302標頭。

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteCond %{REQUEST_URI} !.(gif|jpeg|png|css|js)$
RewriteRule .* /index.html [L]

並檢查DirectoryIndex指令,以默認顯示index.html(如果已更改)

暫無
暫無

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

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