如何将对虚拟主机(子域)的访问限制为少数特定 IP?
问题是该虚拟主机指向与主站点相同的根位置。它只是在 sub.mysite.com 上镜像 www.mysite.com 的内容。这禁止我在 .htaccess 中使用允许和拒绝规则,因为这也会影响 www.mysite.com 流量。我还尝试过使用:
RewriteCond %{HTTP_HOST} ^sub.mysite.com$
RewriteCond %{REMOTE_ADDR} !^123\.45\.67\.89$ [OR]
RewriteCond %{REMOTE_ADDR} !^123\.55\.76\.234$ [OR]
RewriteCond %{REMOTE_ADDR} !^12\.54\.67\.87$
RewriteRule ^.*$ http://www.mysite.com [R=301]
IP 地址不属于某个范围,因此我认为生成单行正则表达式来覆盖所有这些地址是行不通的,并且使用像上面这样的一系列条件根本行不通工作,看起来很乱。上述IP只是示例。我需要限制对大约 10 个唯一 IP 的访问。有什么想法吗?
The catch is that this virtual host points to the same root location as the main site. It is meant to just mirror the content of www.mysite.com on sub.mysite.com. This prohibits me from using allow and deny rules in my .htaccess, since that would affect www.mysite.com traffic as well. I've also tried using:
RewriteCond %{HTTP_HOST} ^sub.mysite.com$
RewriteCond %{REMOTE_ADDR} !^123\.45\.67\.89$ [OR]
RewriteCond %{REMOTE_ADDR} !^123\.55\.76\.234$ [OR]
RewriteCond %{REMOTE_ADDR} !^12\.54\.67\.87$
RewriteRule ^.*$ http://www.mysite.com [R=301]
The IP addresses don't fall into a range, so I think generating a single-line REGEX to cover all of them wouldn't work, and using a series of conditionals like the above simply didn't work, and seemed very messy. The above IPs are just examples. I would need to limit access to roughly 10 unique IPs. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在目录节点下的虚拟主机中定义允许和拒绝。这应该只对您想要的虚拟主机生效。
Try to define allow and deny in the virtualhost under the directory node. That should only take effect on the virtualhost you want to.