.htaccess 密码保护允许 127.0.0.1 但不允许 localhost
我正在尝试使用密码保护我的公用文件夹,以便任何尝试从外部访问的人都会被提示输入密码,但不会在本地输入密码。到目前为止,我已经可以使用 127.0.0.1 但不能使用 localhost 来工作。显然我可以只使用 IP 地址,但更重要的是我想知道为什么它不起作用。我不喜欢被打败!
#Enable Password Protection
AuthName "Password Protected Server"
AuthType Basic
AuthUserFile c:\xampp\apache\security\.htpasswd
Require valid-user
Order allow,deny
Allow from localhost
Allow from 127.0.0.1
Satisfy Any
到目前为止,我的代码是以下内容的积累:
http://www.groovypost.com/howto/how-to/htaccess-password-protect-apache-website-security/
我正在运行 XAMPP 1.7.3 Windows 7,如果有帮助的话。
任何帮助将不胜感激!
I'm attempting to password protect my public folder so that anyone trying to access externally is prompted to enter a password but not locally. So far I have got it to work using 127.0.0.1 but not localhost. Obviously I COULD just used the ip address but it's more the fact I want to know why it doesn't work. I don't like to be defeated!
#Enable Password Protection
AuthName "Password Protected Server"
AuthType Basic
AuthUserFile c:\xampp\apache\security\.htpasswd
Require valid-user
Order allow,deny
Allow from localhost
Allow from 127.0.0.1
Satisfy Any
My code so far is an accumulation of:
http://www.groovypost.com/howto/how-to/htaccess-password-protect-apache-website-security/
htaccess password protect but not on localhost
I'm running XAMPP 1.7.3 on Windows 7, in case that helps.
Any assistance would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来像是 IPv6 问题。当您使用 127.0.0.1 连接到站点时,Apache 会将请求视为来自 IPv4 本地主机 (127.0.0.1)。但是,当连接到本地主机时,Apache 会将请求视为来自 IPv6 本地主机 (::1)。
如果这是问题所在,您应该能够通过将
Allow from localhost
行替换为Allow from ::1
行来解决它。Sounds like an IPv6 issue. When you're connecting to the site with 127.0.0.1, Apache sees the request as coming from the IPv4 localhost (127.0.0.1). But, when connecting to localhost, Apache sees the request as coming from the IPv6 localhost (::1).
If this is the problem, you should be able to solve it by replacing the
Allow from localhost
line with aAllow from ::1
line.