簡體   English   中英

從index.html重定向到/

[英]Redirect from index.html to /

當試圖在目錄和子目錄中訪問index.html時,我需要將301重定向到/。

RewriteRule ^index\.html$ / [L,R=301]

當我嘗試從example.com/index.html重定向時,一切正常,但是當我嘗試從example.com/folder/index.html重定向到example.com/folder/時,它將重定向至/ (在example.com/folder/中的.htaccess中使用相同的代碼)。

請幫助並顯示組織我所需的最佳方法。

最好處理從根.htaccess進行的所有這些重定向,並避免在folder另一個.htaccess。

您可以在根.htaccess中使用此規則:

RewriteCond %{THE_REQUEST} /index\.html [NC]
RewriteRule ^(.*?)index\.html$ /$1 [L,R=301,NC,NE]

定位特定文件夾:

RewriteCond %{THE_REQUEST} /index\.html [NC]
RewriteRule ^((?:folder1|folder2)/)?index\.html$ /$1 [L,R=301,NC,NE]

暫無
暫無

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

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