CentOS Apache .htaccess:此处不允许选项(500 - 内部服务器错误)

时间:2015-12-31 20:57:19

标签: php apache .htaccess mod-rewrite centos7

我在CentOS 7中安装Apache,这是我的 httpd.conf - http://pastebin.com/raw/YeiLn7GN

这是我的文档根目录: / home / host / public_html

测试.htaccess文件是否有效&如果mod_rewrite已启用,我已将示例.htaccess从laravel项目上传到/home/host/public_html/.htaccess,其中包含以下内容:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

然后我上传了以下php脚本:/home/host/public_html/index.php

<?php echo '<pre>'; print_r($_SERVER); ?>

当我访问http://<my-server-ip>/index.php时,我收到以下错误:

  

500内部服务器错误

我在/var/log/httpd/apache_error_log文件中找到了以下内容:

  

[12月31日15:50:43.696465 2015] [core:alert] [pid 23807] [client xxx.xxx.xxx.xxx:56536] /home/host/public_html/.htaccess:此处不允许选项< / p>

如果我从.htaccess文件中删除以下行:

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

脚本似乎加载,没有500错误。

任何想法可能出错?

1 个答案:

答案 0 :(得分:2)

.htaccess:此处不允许的选项错误表示不允许htaccess文件使用Options指令更改设置。

要修复此错误,请编辑您的apache配置文件/etc/httpd/conf/httpd.conf: -

<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride Options
    Order allow,deny
    allow from all
</Directory>

将“选项”添加到AllowOverride列表中,将允许在htaccess文件中使用Options指令