.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/