此处不允许使用 AuthType

koj*_*ow7 6 apache .htaccess

我的 .htaccess 文件去年运行正常,据我所知我没有更改它。但是,我现在收到以下错误:

AuthType not allowed here
Run Code Online (Sandbox Code Playgroud)

我的 .htaccess 文件如下所示:

AuthType Basic
AuthName "Password Protected Area"
AuthUserFile /pwd/.htpasswd
Require valid-user
Run Code Online (Sandbox Code Playgroud)

如果它有助于我的主 apache .conf 文件,该域如下所示:

<VirtualHost *:80>
  ServerAdmin webmaster@example.com
  ServerName subdomain.example.com

  DirectoryIndex index.html index.php
  DocumentRoot /var/sites/example.com/subdomain

  LogLevel warn
  ErrorLog /var/sites/example.com/log/error.log
  CustomLog /var/sites/example.com/log/access.log combined
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

有什么想法可能是什么问题吗?

Dav*_*uer 5

AuthType(和其他指令)不允许“此处”几乎肯定是缺少AllowOverride允许.htaccess文件覆盖指令。

https://httpd.apache.org/docs/current/mod/core.html#allowoverride

AllowOverride只分部分进行<Directory>。解决方案可能如下所示:

<Directory "/var/sites/example.com/subdomain">
    AllowOverride All
</Directory>
Run Code Online (Sandbox Code Playgroud)

.htaccess这将只允许在/var/sites/example.com/subdomain目录中进行覆盖。

指令<Directory>已经存在,您可能希望修改它而不是添加新指令。此搜索有助于在大多数 Linux 系统上找到它:

grep -r "Directory" /etc/httpd/ 
Run Code Online (Sandbox Code Playgroud)