Apache 身份验证:失败时重定向,可靠吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1726860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache authentication: Redirect on failure, reliably?
提问by bukzor
I've set my ErrorDocument 401 to point to my website's account creation page, but not all browsers seem to honor this redirect (Safari).
我已将 ErrorDocument 401 设置为指向我网站的帐户创建页面,但似乎并非所有浏览器都支持此重定向 (Safari)。
Also, other browsers (Firefox, Chrome) never quit asking for the password and show the ErrorDocument. This causes a good number of users to give up trying after many password attempts without seeing the account creation page.
此外,其他浏览器(Firefox、Chrome)永远不会停止询问密码并显示 ErrorDocument。这会导致大量用户在多次尝试密码后没有看到帐户创建页面而放弃尝试。
Is there any way to make the redirect more reliable, without trashing basic authentication altogether?
有什么方法可以使重定向更可靠,而不会完全破坏基本身份验证?
回答by Boris
The simple answer to your question is no, you can't make this more reliable without implementing custom authentication.
您的问题的简单答案是否定的,如果不实施自定义身份验证,您就无法使其更可靠。
The only way that Firefox and Chrome will display page that you specified in the ErrorDocument 401 directive is if you click cancel button. Also, there is no redirect sent with the 401 HTTP code; rather, it is a content of the document specified with ErrorDocument 401 directive. You can do redirect using HTML meta tag:
Firefox 和 Chrome 显示您在 ErrorDocument 401 指令中指定的页面的唯一方式是单击取消按钮。此外,没有使用 401 HTTP 代码发送重定向;相反,它是使用 ErrorDocument 401 指令指定的文档内容。您可以使用 HTML 元标记进行重定向:
<Location "/protected">
AuthUserFile /path/to/users
AuthName "This is protected area"
AuthGroupFile /dev/null
AuthType Basic
Require valid-user
#ErrorDocument 401 /register.html
ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=/register.html\"></html>"
</Location>
Possible solutions to your problem are to create custom basic HTTP authentication module or to use language like php that supports basic HTTP authentication hooks
您的问题的可能解决方案是创建自定义基本 HTTP 身份验证模块或使用支持基本 HTTP 身份验证挂钩的 php 等语言
回答by Josh Pearce
I suspect that your firefox and safari users are not entering the domain before the username i.e. MYDOMAIN\USERNAME. There are some settings in firefox that will allow pass-through authentication; I don't know about safari.
我怀疑您的 firefox 和 safari 用户没有在用户名之前输入域,即 MYDOMAIN\USERNAME。firefox 中有一些设置允许通过身份验证;我不知道野生动物园。

