大网数据广告活动
服务器运维问答

apache24 overriding AuthName in htaccess doesn't work

· 52CE 我爱测

Trying to use AuthName in a .htaccess file to override the top-level config setting doesn't work - the server still sends the value for WWW-Authenticate:"Basic realm="..."" that's set in the config. This is despite having AllowOv…

问题原文

原帖链接 · theultramage · CC BY-SA 3.0

Trying to use AuthName in a .htaccess file to override the top-level config setting doesn't work - the server still sends the value for WWW-Authenticate:"Basic realm="..."" that's set in the config. This is despite having AllowOverride AuthConfig enabled. Am I doing something wrong, or did I find a bug?

httpd.conf:

<Directory "/www">
  AllowOverride AuthConfig
</Directory>

<Location />
  AuthName "config"
</Location>

/www/.htaccess

AuthType Basic
AuthName "htaccess"
AuthUserFile /dev/null
Require user nobody

PS: The real-world version of the above example is having a common top-level 'single sign-on' auth setup, and then just putting the single line "Require valid-user" and such in htaccess files. The conflict happened with a subdirectory that uses a fake auth realm to implement logout for basic auth.

已采纳解答

原帖链接 · MrWhite · CC BY-SA 3.0

As ezra-s suggested in comments, you need to move the AuthName directive out of the <Location> container and set in the <Directory> container.

<Location> containers are processed much later in the request, after <Directory> containers and .htaccess files. So this will be overriding your .htaccess file.

Also, you shouldn't use <Location> containers when dealing with authentication for parts of the filesystem, as they can be circumvented if resources are accessed from multiple URLs.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-10-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。