Apache-2.2

Apache HTTPD:“客戶端被伺服器配置拒絕:.htaccess”即使 .htaccess 為空白

  • October 16, 2013
  • Windows 7 旗艦版(64 位)
  • Apache HTTP 伺服器 2.2.15(32 位)
  • PHP 5.3.2(32 位)

httpd.conf 是預設的,除了我取消註釋 mod_rewrite 的行和載入 httpd-vhosts.conf 的行,它看起來像這樣:

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

<Directory "D:/Path/To/Sites">
 Options Indexes
 Order Deny,Allow
 Allow from all
</Directory>

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
   ServerAdmin me@site1.tld
   DocumentRoot "D:/Path/To/Site 1"
   ServerName site1.local
   ServerAlias www.site1.local
   ErrorLog "logs/site1.local-error.log"
   LogLevel debug
   CustomLog "logs/site1.local-access.log" common
</VirtualHost>

<VirtualHost *:80>
   ServerAdmin me@site2.tld
   DocumentRoot "D:/Path/To/Sites/Site 2"
   ServerName site2.local
   ServerAlias www.site2.local
   ErrorLog "logs/site2.local-error.log"
   LogLevel debug
   CustomLog "logs/site2.local-access.log" common
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot "D:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"
  ServerName localhost
</VirtualHost>

Windows 主機文件將 site1.local 和 site2.local 轉發到 127.0.0.1。

當嘗試訪問 site2.local 時,.htaccess 顯然被忽略了。在 site2.local-error.log 中,每次我嘗試訪問它時唯一的錯誤是:

$$ Wed Jul 21 17:57:06 2010 $$ $$ error $$ $$ client 127.0.0.1 $$客戶端被伺服器配置拒絕:D:/Path/To/Sites/Site 2/.htaccess

但是,即使我刪除了 .htaccess 中的所有內容,我仍然會遇到同樣的錯誤。在 VirtualHost 中移動目錄沒有區別;也不會將站點 2 的內容移動到 htdocs。

顯然 .htaccess 沒有被讀取,因為我不允許配置覆蓋;如果我將“AllowOverride All”添加到我的虛擬主機目錄中,它可以工作——除了 mod_rewrite,由於以下錯誤:

選項 FollowSymLinks 或 SymLinksIfOwnerMatch 關閉,這意味著禁止 RewriteRule 指令

在我添加 Options FollowSymLinks 後,一切正常。

最終程式碼:

<Directory "D:/Path/To/Sites">
 Options Indexes FollowSymLinks
 AllowOverride All
 Order Deny,Allow
 Allow from all
</Directory>

引用自:https://serverfault.com/questions/162802