.htaccess 無法在 Cent Os 6.4 上運行

.htaccess 無法在 Cent Os 6.4 上運行

我已經安裝了Cent Os 6.4 -Final Version並設定了PHP Web開發的環境。

我的應用程式使用 .htaccess 進行 URL 重寫並拒絕直接存取檔案。

我的 httpd 設定檔 - /etc/httpd/conf/httpd.conf 如下,

<Directory "/var/www/html">

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
    Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
    AllowOverride None

#
# Controls who can get stuff from this server.
#
    Order allow,deny
    Allow from all

</Directory>

當我改變了允許覆蓋無允許覆蓋全部,它要求身份驗證。所以它對我不起作用並給出如下錯誤,

This server could not verify that you are authorized to access the document requested.

您提供了錯誤的憑證(例如,錯誤的密碼),或者您的瀏覽器不了解如何提供所需的憑證。

我的 .htaccess 看起來像,

deny from all

答案1

透過AllowOverride Nonehttpd.conf 中的設置,.htaccess 檔案將被完全忽略。所以你必須更改該設定。

當允許 .htaccess 檔案時,apache 會檢查從 DocumentRoot 開始的每個目錄是否存在 .htaccess 文件,並套用那裡的設置,然後再下降到下一個目錄和那裡的 .htaccess 檔案。

例如,./www/.htaccess設定為“拒絕所有”,嘗試存取 /scripts/test/hello-world.php 的訪客將被拒絕,儘管 ./www/scripts/test/.htaccess可能已設定為“允許所有”。

因此,如果您的 PHP 腳本不要求身份驗證,您可能需要檢查更高層級的目錄中是否有 .htaccess 檔案。

相關內容