我有密码保护的网站与.htaccess。我现在想做的是强制用户从index.html页面登录,而不是从他们现在可以做的任何其他地方登录。即。我有index.html (主页),我还有另外两个页面1.html和2.html,也有.htaccess密码保护。用户现在可以输入http://www.mypage.com/1.html,他们将被要求提供登录数据,但我想强制他们(在他们被要求提供登录详细信息之前)使用index.html进行登录。登录后,他们可以随意使用任何链接(例如,1.html或2.html)。
使用.htaccess可以做到这一点吗?我需要完整的代码。谢谢!
发布于 2011-01-08 20:04:43
使用.htaccess,您可以使用密码保护整个目录:
AuthType Basic
AuthName "Restricted Files"
AuthBasicProvider file
AuthUserFile /path/to/passwords/file/passwords
Require user myuser您可以使用以下命令创建密码文件:
htpasswd -c /path/to/passwords/file/passwords myuser你可以在Apache docs中用好的例子来完成描述。
发布于 2011-01-08 20:13:37
如果你使用apache来保护一个目录,你不能在你的index.html上为它创建一个登录表单。登录对话框由浏览器创建。
但是,您可以通过检查referrer标头,强制用户首先访问index.html。如果它存在并且与domain.comindex.html不同,您可以重定向到index.html。为此,您必须使用mod_rewrite。
https://stackoverflow.com/questions/4633710
复制相似问题