【问题标题】:How to put "and" and "or" condition in RewriteCond?如何在 RewriteCond 中放置“and”和“or”条件?
【发布时间】:2014-05-26 11:16:56
【问题描述】:

这是我当前的VirtualHost 节点:

<VirtualHost *:80>
  ServerName abc.com
  ServerAlias abc.com www.abc.com
  RewriteEngine on
  RewriteCond %{HTTPS} !=on
  RewriteRule ^/?(.*) https://%{SERVER_NAME}/ [NC,R,L]
</VirtualHost>

它表示到达此服务器的每个 request:80 都将重定向到 HTTPS。现在我想将orand 条件添加到VirtualHost 节点。因此,它将按如下方式工作:

  • 如果 request:80 来自 xyz.com,则不会重定向到 HTTPS
  • 如果 request:80 来自 abc.com,那么它将重定向到 HTTPS

我应该怎么做?

【问题讨论】:

    标签: apache .htaccess http url mod-rewrite


    【解决方案1】:

    你可以说:

    RewriteCond %{HTTP_HOST} ^(www\.)?abc\.com$ [NC]
    RewriteCond %{HTTPS} off
    RewriteRule ^/?(.*)$ https://%{HTTP_HOST}/$1 [NE,R,L]
    
    RewriteCond %{HTTP_HOST} ^(www\.)?xyz\.com$ [NC]
    RewriteCond %{HTTPS} on
    RewriteRule ^/?(.*)$ http://%{HTTP_HOST}/$1 [NE,R,L]
    

    【讨论】:

    • 我以为你想为 avc.com 强制执行 https
    猜你喜欢
    • 2010-10-29
    • 2021-01-17
    • 2012-05-06
    • 2012-05-07
    • 2013-12-06
    • 2012-06-04
    • 1970-01-01
    • 1970-01-01
    • 2016-10-30
    相关资源
    最近更新 更多