[Apache] 啟用 .htaccess 後出現 500 錯誤的解決方法

在網站啟用 .htaccess 檔案後,如果 Apache 未進行相應設定,就可能出現 500 Internal Server Error 錯誤,如下圖所示:
500

通常可以採取下列措施,透過修改 Apache 設定檔 httpd.conf 來解決這個問題。

可以搭配查看 Apache 安裝目錄下的 logs/error.log,找出問題所在。

1、啟用 mod_rewrite 模組:
搜尋下列這一行,並取消註解:

LoadModule rewrite_module modules/mod_rewrite.so

必須先啟用 mod_rewrite 模組,才能使用 .htaccess 檔案。

2、啟用 mod_filter 模組:
如果出現以下錯誤:
Invalid command 'AddOutputFilterByType', perhaps misspelled or defined by a module not included in the server configuration

搜尋下列這一行,並取消註解:

LoadModule filter_module modules/mod_filter.so

3、啟用 mod_deflate 模組:
如果出現以下錯誤:
.htaccess: Unknown filter provider DEFLATE

搜尋下列這一行,並取消註解:

LoadModule filter_module modules/mod_deflate.so

4、啟用 mod_headers 模組:
如果出現以下錯誤:
.htaccess: Invalid command 'Header'

搜尋下列這一行,並取消註解:

LoadModule headers_module modules/mod_headers.so

Add a Comment

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *