403 Forbidden Acces via .htaccess clean url 但可以直接访问

403 Forbidden Acces via .htaccess clean url 但可以直接访问

有人可以帮我解码我的 apache2 error_log 吗?

[Sat Nov 19 17:39:59 2011] [error] [client ::1] client denied by server configuration: /Library/WebServer/Documents/Users
[Sat Nov 19 17:39:59 2011] [error] [client ::1] client denied by server configuration: /Library/WebServer/Documents/favicon.ico

这个文件夹根本不存在。大多数人都有一个好的客户端地址,例如 127.0.0.1,但由于我使用的是 Mac OS Lion,有人告诉我更新我的 hosts 文件以拥有这个

127.0.0.1   localhost
::1         localhost 
fe80::1%lo0 localhost

我不太清楚问题是什么。如果我导航到以下内容:

http://localhost/kl/n/

我没有遇到任何问题,并且可以看到索引页(由 .htaccess 文件设置为 start.php)。但是,如果我尝试登录:

http://localhost/kl/n/login

应该路由到 http://localhost/kl/n/login/login.php我的 apache2 error_log 中出现了 403 禁止访问错误,上面提到了这些错误。现在我可以毫无问题地访问http://localhost/kl/n/login/login.php。它存在并且运行良好。为了查看是否是地址问题,我为 error_log 创建了一个未定义的变量来抛出,当我直接通过完整 url 访问它时,我的 error_log 中出现此错误:

[Sat Nov 19 18:00:32 2011] [error] [client ::1] PHP Notice:  Undefined variable: orange2 in /Users/myusername/Sites/cloud/kl/n/styles/colors.php on line 127, referer: http://localhost/kl/n/login/login.php

因此对于 403 错误来说:

You don't have permission to access /Users/myusername/Sites/cloud/kl/n/login/login.php on this server.

对我来说有点奇怪。任何帮助或任何检查都将不胜感激。我似乎无法继续前进,因为整个网站都严重依赖这些干净的网址,而且现在在开发中更改所有链接,然后在生产中再次更改,也会非常麻烦。非常感谢。

编辑于 2011 年 11 月 21 日下午 2:42:我决定添加更多信息来帮助任何试图帮助我的人(拜托,伙计们,我不可能是唯一一个遇到这种情况的人,这似乎是其他人一定遇到过的事情。没有 MAMP 用户在其服务器上使用 .htaccess 重写遇到 403 禁止?)

在我的站点文件夹下有一个名为 httpd-vhosts.conf 的文件,它如下:

<Directory "/Users/myusername/Sites"> 
    Options Indexes FollowSymLinks MultiViews 
    AllowOverride All 
    Order allow,deny 
    Allow from all 
</Directory> 

Alias /kl "/Users/myusername/Sites/cloud/kl"

# For http://localhost in the OS X default location 
<VirtualHost _default_:80> 
    ServerName localhost 
    DocumentRoot /Library/WebServer/Documents 
</VirtualHost> 

在 /etc/apache2/httpd.conf 下,我取消了启用 php5 的行的注释,并更改了以下行:

# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.  
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
#User _www
#Group _www
User myusername
Group _www

我尝试使用正常的 _www 和我的用户名,但都无法解决问题。我还更改了 /etc/apache2/httpd.conf 下的这些行

# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
#DocumentRoot "/Library/WebServer/Documents"
DocumentRoot "/Users/myusername/Sites"

#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories). 
#
# First, we configure the "default" to be a very restrictive set of 
# features.  
#
<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
</Directory>

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

#
# This should be changed to whatever you set DocumentRoot to.
#
# old path
#<Directory "/Library/WebServer/Documents">
# new path
<Directory "/Users/myusername/Sites">

再次感谢任何帮助。我真的希望我不是唯一一个在 MAC OS X Lion 上设置 MAMP 并遇到 .htaccess 问题的人。


更新日期:2012 年 1 月 31 日:

我不再安装 Lion,但我在 Snow Leopard 上遇到了类似的问题。我不确定这个修复是否也适用于我,但我还是把它包括在内,以防它对任何人有帮助。基本上,你必须在 .htaccess 中 RewriteEngine On 行后面添加这个

RewriteBase /~myusername/path/to/root/dir

因此,如果您必须指向 localhost/~myusername/first-folder-under-sites,那么您需要添加

RewriteBase /~myusername/first-folder-under-sites

并结合开放的 httpd.conf 设置(即不是我的帖子中的方式,而是不太安全:)

<Directory />
  Options FollowSymLinks
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>

你应该不会有问题。

相关内容