我正在嘗試更改我網站的主頁,但沒有任何反應。在“DirectoryIndex index.html #to make index.html as index”下面輸入代碼時,我的主頁保持不變。我正在更改 .htaccess 中的檔案
<IfModule mod_rewrite.c>
Options FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^index.php - [L]
RewriteRule ^index.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
#RewriteRule ^(.*)$ index.php [QSA,L]
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
DirectoryIndex index.html #to make index.html as index
我的網站是用 php 撰寫的,我想把主頁放在 html 中
uj5u.com熱心網友回復:
RewriteRule ^(.*)$ index.php [QSA,L]
*將量詞更改為 ,使其僅匹配非空 URL 路徑,以允許DirectoryIndex檔案(即。index.html)為主頁請求提供服務,而不是將請求傳遞給前端控制器(即。index.php)。或者,只需使用點 ( .) 作為正則運算式,因為您沒有對捕獲的 URL 路徑執行任何操作。例如:
RewriteRule . index.php [L]
(QSA這里不需要標志。)
雖然,由于您使用的是前端控制器模式(即,將所有請求路由到index.php),但您可能應該配置適當的回應來提供服務index.php?
在旁邊:
DirectoryIndex index.html #to make index.html as index
您應該洗掉您認為是行尾的注釋,即。“ #to make index.html as index”。這實際上不是評論。Apache 不支持行尾注釋(僅支持全行注釋)。在這種情況下,#to、make、index.html和as將index被視為DirectoryIndex指令的附加引數(因此您實際上不會得到錯誤)。
請參閱我對以下關于使用行尾注釋的問題的回答:
錯誤 500: .htaccess RewriteCond: bad flag delimiters
更新:
替代解決方案
請嘗試以下操作(這將替換上面的整個 .htaccess檔案):
Options FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^index\.(php|html)$ - [L]
# Rewrite any request for anything that is not a file to "index.php"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
# Rewrite the homepage only to "index.html"
RewriteRule ^$ index.html [L]
<IfModule>不需要包裝器。(這是您的服務器,因此您知道是否啟用了 mod_rewrite,并且這些指令不是可選的。)
確保在測驗之前清除了瀏覽器快取。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/449233.html
