RewriteCond 在 .htaccess 上不正确匹配

RewriteCond doesn't match properly on .htaccess

我想将 ipv4 地址 (51.255.51.165) 和 VPS url 服务器 (vps227127.ovh.net) 指向一个域。

我已经尝试在 .htaccess 中使用这个重写规则:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^vps227127.ovh.net$
RewriteCond %{HTTP_HOST} ^51\.255\.51\.165
RewriteRule (.*) http://krioma.com/ [R=301,L]

第二个条件正常,它将 301 重定向到 http://krioma.com,但似乎忽略了第一个条件。也许我错了。

有什么建议吗?

使用:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^vps227127.ovh.net$ [NC,OR]
RewriteCond %{HTTP_HOST} ^51\.255\.51\.165
RewriteRule (.*) http://krioma.com/ [R=301,L]

因为没有 OR 它是隐含的 AND

通常情况下,如果您没有明确告诉 Apache 您想要其中任何一个,它将使用默认值 AND 并且两个条件都必须为真才能工作。您需要使用特殊的 OR 标志,以便如果满足其中一个,则继续执行重写规则。

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^vps227127.ovh.net$ [OR]
RewriteCond %{HTTP_HOST} ^51\.255\.51\.165
RewriteRule (.*) http://krioma.com/ [R=301,L]