【问题标题】:Turning RewriteEngine on creates 403 error--how to turn on FollowSymLinks?打开 RewriteEngine 会产生 403 错误——如何打开 FollowSymLinks?
【发布时间】:2014-05-02 12:46:27
【问题描述】:

我正在使用 OSX 上的内置 Apache2。我将文档根目录移动到桌面上的文件夹中,并确保 _www 和 everyone 具有读取权限。它工作得很好,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] 选项 FollowSymLinks 或 SymLinksIfOwnerMatch 关闭,这意味着禁止 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 还有什么地方可以打开(或关闭)?

【问题讨论】:

    标签: apache mod-rewrite apache2 symlink httpd.conf


    【解决方案1】:

    您必须将您的选项放在一行中,或者在您的选项前面添加一个+ 符号,以便 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>
    

    【讨论】:

    • FollowSymLinks 和 SymLinksIfOwnerMatch 不应该在一起,因为 Apache 如何尊重它们,因为它们的行为不同。
    • @god_is_love 虽然将它们一起使用可能不是很好的形式,但这肯定不是错误。 Apache 会简单地使用更具体的选项而忽略另一个。 OP 最初的问题是他们如何使用选项。这是我选择关注的。请更明智地使用您的反对票。这不是对否决票的建设性使用。
    【解决方案2】:

    我遇到了 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多