【问题标题】:RewriteCond doesn't match properly on .htaccessRewriteCond 在 .htaccess 上不正确匹配
【发布时间】:2015-12-15 23:55:47
【问题描述】:

我只想将 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/$1 [R=301,L]

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

有什么建议吗?

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect rewrite


    【解决方案1】:

    用途:

    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

    【讨论】:

      【解决方案2】:

      通常,如果您没有明确告诉 Apache 您想要其中一个,它将使用默认的 AND 并且两个条件都必须为真才能工作。您需要使用特殊的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]
      

      【讨论】:

        猜你喜欢
        • 2016-10-16
        • 2012-07-24
        • 1970-01-01
        • 2022-09-23
        • 2014-06-24
        • 2023-01-25
        • 2012-11-02
        • 2020-04-05
        • 1970-01-01
        相关资源
        最近更新 更多