Apache .htaccess 設定 RewriteEngine On 後網站出現 403 Forbidden

  用 Joomla 4 建置新網站開啟 SEO 及 URL Rewrite 後網站就出現問題一開始 Google 到自己的文章 -「Joomla URL rewrite 404 無法顯示網頁主要是因為沒把 httpd.conf 的 AllowOverride 設為 All 導致但這次設完後卻變成 403 Forbidden且是所有頁面都進不去不管該頁網址有沒有用到 rewrite研究了幾個小時總算找到原因

 

要使用 URL Rewrite有下列設定值需設定

1. ApacheLoadModule rewrite_module
2. ApacheOptions FollowSymLinks
3. ApacheAllowOverride All
4. .htaccessRewriteEngine On

 

  而我的問題在於以上四個都已設定卻出現 403 Forbidden其中 2. 3. 我在 httpd.conf 及 httpd-ahssl.conf 皆試過

 

  為了簡化測試環境以釐清問題我將 .htaccess 內容只留下 RewriteEngine On 這行字並將檔案放在 htdocs 根目錄另外製作一個 test.php 檔內容如下單純顯示 php 環境資訊此檔同樣放在 htdocs 根目錄

<?php
phpinfo();
?>

 

  當瀏覽 http://abc.com/test.php 時同樣出現 403 Forbidden而去查詢 Apache 的 error.log 時可以看到這樣的錯誤

Options FollowSymLinks and SymLinksIfOwnerMatch are both off, so the RewriteRule directive is also forbidden due to its similar ability to circumvent directory restrictions : C:/Web/Apache24/htdocs/test.php

 

  因此可以將問題的範圍縮小到 FollowSymLinks 這個參數上再三確認 httpd.conf 有正確設定 FollowSymLinks 後我開始逐一檢視與比對新舊網站的 httpd.conf 差異後來注意到新網站除了在 SSL 的部份是引用 httpd-ahssl.conf (Include conf/extra/httpd-ahssl.conf) 設定檔外FastCGI 的部份也是引用外部 httpd-fcgid.conf (Include conf/extra/httpd-fcgid.conf) 設定檔也就是說我舊網站的設定都在 httpd.conf但新網站是用到三個設定檔(httpd.confhttpd-ahssl.confhttpd-fcgid.conf)。其中 httpd.conf 跟 httpd-ahssl.conf 我已經試過所以問題的癥結應該就在 httpd-fcgid.conf

 

  打開 httpd-fcgid.conf 底下找到 Options預設只有一個 ExecCGI 參數在後面加上 FollowSymLinks 後重啟 Apache問題總算解決

 

【相關連結】

3 則留言

  1. Anonymous says:

    Is FortiGate 50E 6.2.10 the best?

    https://it-help.tips/fortigate-firmware-download/

    Help!

  2. Anonymous says:

    Is FortiGate 50E 6.2.10 the best?

    1. Anson says:

      Yes.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.