RewriteCond在.htaccess上没有正确匹配

时间:2015-12-15 14:38:15

标签: apache .htaccess mod-rewrite redirect rewrite

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

我在.htaccess中试过了这个重写规则:

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

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

有什么建议吗?

2 个答案:

答案 0 :(得分:3)

使用:

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

因为没有OR它隐含AND

答案 1 :(得分:2)

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

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