所有指令均出现 .htaccess 错误“此处不允许”

所有指令均出现 .htaccess 错误“此处不允许”

我正在使用 Debian Lenny 和 Apache 2。我使用以下命令更改了默认.htaccess文件:

AllowOverride AuthConfig

not allowed here但是当我在文件中输入任何指令时, 我总是收到错误消息.htaccess

编辑:

文件默认:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/

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

        <Directory /var/www/>
                Options Indexes FollowSymLinks Includes
                #AllowOverride All
                #AllowOverride Indexes AuthConfig Limit FileInfo
                AllowOverride AuthConfig
                Order allow,deny
                Allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined

        Alias /doc/ "/usr/share/doc/"
        <Directory "/usr/share/doc/">
                Options Indexes MultiViews FollowSymLinks 
                AllowOverride None
                Order deny,allow
                Deny from all
                Allow from 127.0.0.0/255.0.0.0 ::1/128
        </Directory>

</VirtualHost>

.htaccess 文件:

#Options +FollowSymlinks

# Prevent Directoy listing
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini)">
 Order deny,allow
 Deny from all
</FilesMatch>

# SEO URL Settings
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA]

PHP信息:

apache2handler

Apache Version = Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny10 with Suhosin-Patch 
Apache API Version = 20051115 
Server Administrator = webmaster@localhost 
Hostname:Port = hw-linux.homework:80 
User/Group = www-data(33)/33 
Max Requests = Per Child: 0 - Keep Alive: on - Max Per Connection: 100 
Timeouts = Connection: 300 - Keep-Alive: 15 
Virtual Server = Yes 
Server Root  = /etc/apache2 
Loaded Modules =

core mod_log_config mod_logio prefork http_core mod_so mod_alias mod_auth_basic
mod_authn_file mod_authz_default mod_authz_groupfile mod_authz_host mod_authz_user
mod_autoindex mod_cgi mod_deflate mod_dir mod_env mod_mime mod_negotiation 
mod_php5 mod_rewrite mod_setenvif mod_status 

答案1

你至少需要AllowOverride Authconfig FileInfo 选项在您的<Directory>块内,使.htaccess您在此处发布的能够工作 -mod_rewrite将需要FileInfo Options并且您的<FilesMatch>块需要Authconfig

另外:您说的“不适用于 AllowOverride All”是错​​误的。您无法指定比 更宽松的环境AllowOverride All。如有疑问,请从此开始,以确保其余配置有效,然后更具体地缩小范围(为了安全起见)。

答案2

此选项只能在Directory元素内部使用。因此您必须指定要保护的目录。

答案3

此处不允许通常是由于尝试在.htaccess只能在 中定义的文件httpd.conf

第一次尝试

AllowOverride All

在您的最下方<Directory>标签中,找到您的 www 文件夹。现在您的.htaccess可以充分发挥作用。如果这解决了问题,那么您可以开始关注安全性并逐一减少允许的指令数量。

相关内容