1

你好~这是我在stackoverflow上的第一篇文章

我们试图在我们的 htaccess 文件中满足以下条件:

如果你不在某个IP地址范围(111.222.xxx.xxx)且http主机是test.com,那么带用户到test.com/goodbye:

RewriteCond %{REMOTE_ADDR} !^111\.222
RewriteCond %{HTTP_HOST} ^test\.com$
RewriteRule ^.*$ http://test.com/goodbye [R=301,L]

如果您在某个 IP 地址范围内(111.222.xxx.xxx)并且 https 主机是 test.com 则将用户带到 test.com/hello:

RewriteCond %{REMOTE_ADDR} ^111\.222
RewriteCond %{HTTP_HOST} ^test\.com$
RewriteRule ^.*$ http://test.com/hello [R=301,L]

无论我使用哪个 IP,我都会被带到 /hello。我假设第一个条件以某种方式失败?

4

1 回答 1

1

颠倒规则并使您的正则表达式更加严格:

RewriteCond %{REMOTE_ADDR} ^111\.222\.
RewriteCond %{HTTP_HOST} ^test\.com$
RewriteRule !^hello /hello [R=301,L]

RewriteCond %{REMOTE_ADDR} !^111\.222
RewriteCond %{HTTP_HOST} ^test\.com$
RewriteRule !^goodbye /goodbye [R=301,L]
于 2014-02-11T15:29:21.023 回答