.htaccess 密码保护不适用于 ErrorDocument 401

.htaccess password protection not working with ErrorDocument 401

我在 /demo/.htpasswd 下有文件 .htpasswd 并且有以下代码

admin:71.HeoDicWfCM

我还有一个文件夹 /demo/fb/,这里我有 .htaccess 文件,代码如下

AuthType Basic 
AuthName "Secured Area" 
AuthUserFile "/demo/.htpasswd" 
require valid-user 
ErrorDocument 401 "Authorisation Required"

我收到弹出窗口,但当我输入用户名和密码时,它显示 404 页面

有什么想法吗?

表示没有找到您的用户,您需要先创建该用户才能使用

您根本不需要创建用户。好像你的 htpasswd 路径不正确

尝试使用以下代码查找完整路径。

<?php
$dir = dirname(__FILE__);
echo "<p>Full path to this dir: " . $dir . "</p>";
echo "<p>Full path to a .htpasswd file in this dir: " . $dir . "/.htpasswd" . "</p>";
?>

在 .htaccess 中使用 htpasswd 的完整路径