Apache RewriteEngine On causes 403 error

时间:2015-04-23 05:13:40

标签: linux apache .htaccess mod-rewrite centos6

I have a Linux box running Centos 6.6 with Apaches 2.2.x For some unknown reason, turning on the rewrite engine causes a 403 error (this happens whether I add a rewrite rule or not).

I have spent hours researching this and have made changes to my config in accordance with advice I have found in many places, but still got nowhere.

Currently in my .htaccess I have this:

<IfModule mod_rewrite.c>  
Options +FollowSymLinks  
RewriteEngine On  
</IfModule>

In the directives for the virtual host, I have this:

DocumentRoot /var/www/html/example.uk  
<Directory /var/www/html/example.uk>  
Options Indexes FollowSymLinks MultiViews  
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerName example.uk  
ServerAlias www.example.uk

(This seems to work in a Debian box, but not for my Centos machine.)

In my httpd.conf I have changed

AllowOverride None

to

AllowOverride All

my httpd.conf also contains LoadModule rewrite_module modules/mod_rewrite.so

Error log says:

Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /var/www/html/example.uk

Now, I have previously added SymLinksIfOwnerMatch to the directives, but it didn't solve the problem.

I followed this and all seemed to go as it should.

4 个答案:

答案 0 :(得分:2)

由于apache版本&gt; = 2.4指令

Order allow,deny
allow from all

导致全局403,如果你检查你是ap​​ache的日志,确保这个:

  

[Tue May 05 11:54:32.471679 2015] [authz_core:error] [pid 9497] [client 127.0.0.1:35908] AH01630:服务器配置拒绝客户端:/ path / to / web /

评论指令Order并添加Require all granted如下:

 Require all granted
 #Order allow,deny
 #allow from all

希望得到这个帮助。

修改:

explanation from apache 此行为由新模块mod_authz_host

提供

可用限制列表(ip,host等)http://httpd.apache.org/docs/2.4/en/mod/mod_authz_host.html

答案 1 :(得分:1)

你应该从htaccess中删除这一行

Options +FollowSymLinks

你已经在apache vhost文件中拥有它了。此外,如果您要添加规则,如果您要打开mod_rewrite,或者没有必要将其打开。

答案 2 :(得分:1)

当Apache没有

的执行权限时会发生这种情况
/var
/var/www
/var/www/html
/var/www/html/example.uk  

执行命令

chmod o+x /var /var/www /var/www/html /var/www/html/example.uk 

答案 3 :(得分:0)

Apache 2.4的另一种可能性是由Options -FollowSymlinks引起的,它还会引发403错误并生成以下日志:

AH00670:选项FollowSymLinks和SymLinksIfOwnerMatch均关闭, 因此RewriteRule指令也被禁止,因为它与 规避目录限制的能力

原始帖子中不是这种情况,但是如果出现此错误,则需要使用此行重新启用FollowSymLinks:

Options +FollowSymLinks