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

  用 Joomla 4 建置新網站,開啟 SEO 及 URL Rewrite 後,網站就出現問題,一開始 Google 到自己的文章 -「Joomla URL rewrite 404 Unable to display webpage」,主要是因為沒把 httpd.conf 的 AllowOverride 設為 All 導致。但這次設完後,卻變成 403 Forbidden,且是所有頁面都進不去,Whether or not the page URL uses rewrite,After researching for a few hours,Finally found the reason。

 

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

1. Apache – LoadModule rewrite_module
2. Apache – Options FollowSymLinks
3. Apache – AllowOverride All
4. .htaccess – RewriteEngine On

 

And my problem is that all four of the above have been set,卻出現 403 Forbidden,Among them 2. And 3. I have tried it in both httpd.conf and httpd-ahssl.conf。

 

To simplify the test environment and clarify the problem,I only left the line RewriteEngine On in the .htaccess file,And placed the file in the htdocs root directory。Additionally, I created a test.php file,The content is as follows,Simply to display PHP environment information,This file is also placed in the htdocs root directory。

<?php
phpinfo();
?>

 

When browsing 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.conf、httpd-ahssl.conf、httpd-fcgid.conf)。其中 httpd.conf 跟 httpd-ahssl.conf 我已經試過,所以問題的癥結應該就在 httpd-fcgid.conf

 

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

 

[Related Links]

3 Leave a comment

  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.