打开RewriteEngine会导致403错误 - 如何打开FollowSymLinks?

5

我正在使用OSX上内置的Apache2。我将文档根目录移动到桌面上的一个文件夹,并确保_wwweveryone都具有读取访问权限。它工作得很好,PHP也可以工作,直到我仅添加了这一行.htaccess

RewriteEngine on

一旦我这样做,文件所在目录中的所有内容都会被禁止访问(403 Forbidden):

Forbidden
You don't have permission to access /dir/file.txt on this server. 

Apache日志显示以下错误:

[error] [client 127.0.0.1] Options FollowSymLinksSymLinksIfOwnerMatch关闭,这意味着 RewriteRule 指令被禁止:/Users/uname/Desktop/localhost/dir/filename.txt

我已经检查了 httpd.conf 并确保我已启用 FollowSymLinks ,但没有任何效果:

DocumentRoot "/Users/uname/Desktop/localhost"
<Directory />
    Options FollowSymLinks
    Options SymLinksIfOwnerMatch 
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

<Directory "/Users/uname/Desktop/localhost">
    Options FollowSymLinks
    Options SymLinksIfOwnerMatch 
    Options Indexes MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

如果我在.htaccess文件中注释掉RewriteEngine on,那么除了重写规则其他一切正常。在OSX 10.8.5上,httpd.conf文件位于/etc/apache2目录下,该目录中还有一个名为users的文件夹,其中包含用户的各个配置文件,如uname.conf,但我已经像在其他文件夹中一样添加了符号链接。我注意到还有一个extra文件夹,里面有像httpd-userdir.conf之类的文件,但它们似乎没有禁用任何东西。
FollowSymLinks在哪里可以被打开或关闭?
2个回答

5
你需要将选项放在一行内,或在选项前面加上+符号,以便Apache理解您要合并它们。目前只有最后一个Options指令('Options Indexes MultiViews')被应用,因为它正在覆盖之前的所有Options。
尝试这样做(这将覆盖“/”选项):
<Directory "/Users/uname/Desktop/localhost">
   Options Indexes MultiViews FollowSymLinks SymLinksIfOwnerMatch
   AllowOverride All
   Order allow,deny
   Allow from all
</Directory>

FollowSymLinksSymLinksIfOwnerMatch不应该同时使用,因为它们的行为不同,Apache如何同时遵循两者。 - god_is_love
虽然同时使用它们可能不是一个好的形式,但这绝对不是一个错误。Apache将简单地使用更具体的选项并忽略其他选项。OP最初的问题在于他们如何使用选项。这就是我选择关注的内容。请更明智地使用你的反对票。这不是一个建设性的反对。 - codnodder

0

我在获取403错误时遇到了问题,解决方法是改变重写规则。我的完整指令如下:

<Directory "/var/www/">

<LimitExcept GET POST HEAD>
  Order Allow,Deny
  Deny from all
  Satisfy all
</LimitExcept>

Require all granted
AllowOverride None

# Disable includes and cgi
Options -Includes
Options -ExecCGI

<IfModule mod_rewrite.c> 

RewriteEngine On

# Redirdect to HTTPS
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule ^(.*)$ - [F,L]

# Put your installation directory here:
RewriteBase /

# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# remove index.php
RewriteRule ^(.*)$ /index.php/$1 [L]

# If your host requires forcing query strings.
# Notice the question at the end of index.php 
# on the last rule
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ /index.php?/$1 [L]

</IfModule> 

</Directory>
ServerName www.example.com
ServerAlias www.example.com

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接