Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

Apache httpd.conf 設定啟用 .htaccess 支援 (AllowOverride All) 完整步驟

編輯:關於伺服器

目的

讓本地 Apache 伺服器識別並套用目錄層級的 .htaccess 設定檔 (URL 重寫、存取控制、自訂錯誤頁等)。

操作步驟

  1. 以文字編輯器開啟 Apache 設定檔 httpd.conf (位於 Apache安裝目錄\conf\httpd.conf)。
  2. 搜尋 <Directory /> 區塊 (根目錄設定),預設內容如下:
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
  1. 將 AllowOverride None 修改為 AllowOverride All:
<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>
  1. 儲存檔案,重新啟動 Apache 服務 (httpd -k restart 或服務管理器重啟)。

驗證方式

  1. 在網站根目錄建立 .htaccess,內容例如:
RewriteEngine On
RewriteRule ^test\.html$ index.php [L]
  1. 瀏覽 https://localhost/test.html 若正確重寫至 index.php 即表示生效。

補充說明

  • AllowOverride All 允許 .htaccess 覆蓋所有可覆蓋指令 (AuthConfig、FileInfo、Indexes、Limit、Options 等)。
  • 生產環境建議僅在必要的虛擬主機/目錄開啟,避免效能影響 (每次請求需遞迴讀取 .htaccess)。
  • Apache 2.4+ 亦可使用 AllowOverrideList 精確控制允許指令集。
Copyright © Windows教程網 All Rights Reserved