在请求/而不是/index.php时获得"需要身份验证"

fti*_*sem 7 apache .htaccess

在我的服务器上,我有以下.htaccess文件:

DirectoryIndex index.php

AuthType Basic
AuthName "Password Required"
AuthUserFile /var/www/webinterface/.htpasswd
Options +FollowSymLinks
Require valid-user

<Files index.php>
    Satisfy any
    Allow from *
</Files>
Run Code Online (Sandbox Code Playgroud)

如果我请求URL"IP-ADDRESS/index.php",一切正常,我得到index.php没有身份验证提示.但是,只要我请求"IP-ADDRESS /",浏览器就会要求我提供凭据.

为什么会这样?我错过了什么?

Jon*_*Lin 8

尝试替换块以使用mod_setenvif来检查请求URI而不是使用<Files>.该的mod_auth*模块拥有mod_dir优先,因此从映射//index.php不会发生,直到AUTH发生之后.Mod_setenvif将在auth之前发生.尝试:

SetEnvIf Request_URI "^/$" allow=yes
SetEnvIf Request_URI "^/index.php$" allow=yes

AuthType Basic
AuthName "Password Required"
AuthUserFile /var/www/webinterface/.htpasswd
Options +FollowSymLinks
Order Deny,Allow
Satisfy any
Deny from All
Require valid-user
Allow from env=allow
Run Code Online (Sandbox Code Playgroud)

如果请求的URI完全//index.php,则变量allow设置.Auth行之后的内容表示拒绝除有效用户之外的所有内容或者allow已设置变量.