萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 伺服器教學

Apache 設定預設首頁 (DirectoryIndex) 完整步驟

修改 httpd.conf

  1. 找到 Apache 安裝目錄下的 conf/httpd.conf
  2. 搜尋 DirectoryIndex 指令
  3. 修改為優先順序列表,例如:
    DirectoryIndex index.php index.html index.htm index.html
    
  4. 存檔並重啟 Apache:apachectl restart 或 systemctl restart httpd

關鍵細節

  • 檔名之間以空格分隔,依序嘗試。
  • 以 # 開頭的行為註解,修改時請移除行首 #。
  • 可針對特定目錄在 .htaccess 或 <Directory> 區塊覆寫。

其他常見設定

# 伺服器根目錄
ServerRoot "/usr/local/apache2"

# 網站文件根目錄
DocumentRoot "/var/www/html"

# 允許 .htaccess 覆寫

    AllowOverride All
    Require all granted

驗證

瀏覽器訪問 https://your-domain/,應自動載入 index.php(若存在),否則依序嘗試 index.html 等。

copyright © 萬盛學電腦網 all rights reserved