允许从一个 IP 访问 url

Allow access to url from one IP

尝试使用 htaccess 仅允许通过一个 IP 地址访问 url。我关注了一些关于该主题的 Whosebug 帖子,但无济于事。

 RewriteCond %{REMOTE_ADDR} !^123\.45\.45\.6
 RewriteCond %{REQUEST_URI} http://sub.domain.com/thatThing [NC]
 RewriteRule ^(.*)$ http://sub.domain.com [R=307,L]

所以我对此的理解是: 1.如果请求不是来自这个IP地址 2.如果请求的URL是http://sub.domain.com/thatthing 3. 跳转到首页

当我对此进行测试时,页面 http://sub.domain.com/thatthing 可从任何 IP 访问。我什至尝试过代理来确定。有没有我遗漏的语法?

提前致谢。

您无法使用 %{REQUEST_URI} 匹配 RewriteCond 中的域名。像这样使用它:

RewriteCond %{REMOTE_ADDR} !^123\.45\.45\.6$
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^thatThing / [R=307,NC,L]