.htaccess - .htpasswd 文件导致服务器错误?

标签 .htaccess .htpasswd

.htaccess 文件背后的代码:

AuthType Basic  
AuthName "restricted area"  
AuthUserFile ".htpasswd" 
require valid-user

.htpasswd 文件背后的代码:

user121:$apr1$bVI1xobF$2ius9YiPaElsFDjD2DK5/0

我使用正确的凭据登录,这是我每次登录时得到的信息:

Server error!

The server encountered an internal error and was unable to complete your request.
Either the server is overloaded or there was an error in a CGI script.

If you think this is a server error, please contact the webmaster.

Error 500

更新:

Apache 错误日志:

[Fri Jun 06 20:42:30.503554 2014] [authn_file:error] [pid 7536:tid 1760] (OS 2)
The system cannot find the file specified.  : [client ::1:58747] AH01620: Could
not open password file: C:/xampp/apache/.htpasswd, referer: 
http://localhost/manage/articles/

I cannot place the file in xampp/apache folder on my webhost?

最佳答案

错误日志显示您使用了错误的 .htpasswd 文件路径:

Could not open password file: C:/xampp/apache/.htpasswd

这告诉您它不位于 C:/xampp/apache 中。确保在 .htaccess 文件中使用正确的路径。例如。如果您的 .htpasswd 位于 C:/xampp/apache/htdocs/myproject/.htpasswd 下,请按此设置。

AuthUserFile C:/xampp/apache/htdocs/myproject/.htpasswd

(虽然最好的做法是将 .htpasswd 放入 htdocs/httpdocs 中,但我只是使用此路径作为示例。)

如果您确定路径正确(因为您似乎使用的是 Windows 安装),请确保该文件实际上名为 .htpasswd。 Windows 无法从资源管理器执行此操作(它禁止创建“仅扩展”文件),您必须从基于命令行的工具执行此操作。如果您在记事本等中创建了 .htpasswd,该文件现在很可能实际上称为 .htpasswd.txt,请使用命令行将其重命名为 .htpasswd:

C:\> cd C:\xampp\apache
C:\xampp\apache> move .htpasswd.txt .htpasswd

关于.htaccess - .htpasswd 文件导致服务器错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24078703/

相关文章:

.htaccess - htaccess : how to redirect all pages to a holding page

apache - 如何确定Apache以什么用户和组身份运行?

javascript - 如何使用密码保护某些 HTML 页面的安全?

php - 通过 CURL 登录 htpasswd 并将 session 保留在浏览器中

php - 使用 htaccess 重写规则访问相关 CSS/JS 文件

.htaccess 将根重定向到子文件夹

.htaccess URL 重写不适用于 Ecwid 产品链接

gitlab - 使用 htpasswd 密码保护 GitLab 页面

apache - 使用 .htaccess 和 .htpasswd 密码保护网站 - 错误 - "Could not open password file:"

php - 如何使用 htaccess 重定向多参数 url