简体   繁体   English

htaccess给出500-内部服务器错误

[英]htaccess gives 500 - Internal Server Error

I am protecting a html file with htaccess and htpasswd. 我使用htaccess和htpasswd保护html文件。 When I try accessing it, after putting both user and password, instead of loading the "index.html" file I get a "500 - Internal Server Error" 当我尝试访问它时,同时输入用户名和密码,而不是加载“ index.html”文件,我得到的是“ 500-内部服务器错误”

AuthName "Restricted Area" 
AuthType Basic 
AuthUserFile home/folder/index.html/.htpasswd 
AuthGroupFile /dev/null 
require valid-user

Any suggestions? 有什么建议么? Maybe something with the hosting service? 也许与托管服务有关?

First of all, consult the error-log (usually located in /var/log/apache2/error.log ) to see the exact cause of the error. 首先,请查阅错误日志(通常位于/var/log/apache2/error.log )以查看错误的确切原因。

If you do not have access to it, check the following: 如果您无权访问,请检查以下内容:

  • is this technique supported by the server? 服务器支持此技术吗? (ask your provider or admin) (询问您的提供者或管理员)
  • is AuthUserFile correct? AuthUserFile是否正确? It seems to be missing a slash and the directory is unusual. 它似乎缺少斜杠,并且目录不寻常。 I would have suspected something like AuthUserFile /home/webuser/sitefolder/.htpasswd . 我会怀疑像AuthUserFile /home/webuser/sitefolder/.htpasswd类的东西。
  • change the group-file to AuthGroupFile None instead of pointing apache to read /dev/null . 将组文件更改为AuthGroupFile None而不是将apache指向读取/dev/null Think of /dev/null as a bottom-less trashcan. /dev/null视为无底垃圾箱。 It's not easy to get anything from there and might be a reason for the server to fail trying. 从那里获取任何东西都不容易,这可能是服务器尝试失败的原因。
  • change the case of your require to Require valid-user . 将您的require的大小写更改为Require valid-user It needs to be a capital R. 它必须是大写R。

To sum up: 总结一下:

AuthName "Restricted Area" 
AuthType Basic 
AuthUserFile /home/webuser/sitefolder/.htpasswd 
AuthGroupFile None
Require valid-user

For further info, I recommend http://httpd.apache.org/docs/ . 有关更多信息,我建议http://httpd.apache.org/docs/

I know the question is a little old, but for those struggling to find the answer, make sure the path to AuthUserFile is correct and access to the .htpasswd file is set to 0655. 我知道这个问题有点老了,但是对于那些努力寻找答案的人,请确保AuthUserFile的路径正确,并将对.htpasswd文件的访问权限设置为0655。

The file is being read by the user associated with the .htaccess file. 与.htaccess文件关联的用户正在读取该文件。 If that user cannot execute it (ie if it's set to 644, etc.), the server cannot read the file to authenticate it and you get a permissions error, ie an Error 500. 如果该用户无法执行该文件(即,如果将其设置为644等),则服务器将无法读取该文件以对其进行身份验证,并且您会收到权限错误,即错误500。

Now this question is older still , but I thought I'd also chime in because I didn't find the solution that eventually worked for me anywhere. 现在,这个问题是旧的还是 ,但我想我还附和,因为我没有找到最终的任何地方为我工作的解决方案。 Besides, it is still unanswered. 此外,它仍然悬而未决。

I too was getting a 500 error on my password .htaccess, and according to the error log, it was due to an "AuthName takes one argument" problem. 我的密码.htaccess也收到500错误,并且根据错误日志,这是由于“ AuthName带一个参数”问题。 After pounding my head against this for way too long, I finally noticed I had "curly" quotes around the AuthName, as opposed to the correct straight quotes. 在我为此花费了太长时间之后,我终于注意到我在AuthName周围有“弯曲”的引号,而不是正确的直接引号。 I replaced these, confident that I had fixed my issue. 我替换了这些,并确信自己已解决了问题。

Still, 500. Nearly threw my laptop out the window. 仍然是500。差点把我的笔记本电脑扔到窗外。 At this point my code looked like this: 此时,我的代码如下所示:

# PW PROTECT INT DIRECTORY
AuthType Basic
AuthName "Login"
AuthUserFile /home/mywebsite/mywebsite.com/reports/int/.htpasswd
require valid-user

Six ways till Sunday later, as a desperate hail Mary, I removed a comment I had diligently included at the very top of the file (gotta include those comments). 直到星期日之后的六种方法,作为绝望的玛丽,我删除了我努力地在文件开头添加的注释(必须包含这些注释)。 That did it, 500 resolved. 做到了,有500个解决了。 Finally. 最后。

I can't speak to why this was parsed as an AuthName problem in the error logs, but I think my problem all came down to trying to copy/paste the code through a less-than-ideal "plain text" editor (in this case, Apple's TextEdit, which was also responsible for those cute curly quotes, present even in plain text mode). 我无法说出为什么在错误日志中将其解析为AuthName问题,但是我认为我的问题全部归结为试图通过不太理想的“纯文本”编辑器复制/粘贴代码(在此例如Apple的TextEdit,它也负责那些可爱的弯引号,即使在纯文本模式下也是如此。 This is an error I'll not be repeating. 这是我不会重复的错误。

I don't know if the "#" hash character is somehow goofy in TextEdit, or if there's some issue with line 1 being a comment, amounting to a blank line (not seen that anywhere), but removing the comment line did it (if anyone knows why, I'd love to hear it). 我不知道TextEdit中的“#”哈希字符是否有点愚蠢,或者第1行是否存在注释,等于空行(在任何地方都看不到),但是删除注释行确实可以解决这个问题(如果有人知道为什么,我很想听听)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM