web.config将多个域重定向到一个并将HTTP重定向到HTTP

时间:2016-02-11 17:14:41

标签: redirect iis

我正在使用web.config将所有HTTP流量重定向到HTTPs网站

<rule name="Redirect to https" stopProcessing="true">
    <match url="(.*)" />
        <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>

这很好用。

我的客户希望我现在将一大堆其他非HTTP .com域名重定向到此HTTP。..。域名。

我找到了一个重定向脚本:

<rule name="Redirect to www.MYDOMAIN.co.uk" patternSyntax="ECMAScript" stopProcessing="true">
    <match url=".*" />
        <conditions logicalGrouping="MatchAny">
            <add input="{HTTP_HOST}" pattern="^(www.)?MYOTHERDOMAIN1.(com|org)$" />
            <add input="{HTTP_HOST}" pattern="^(www.)?MYOTHERDOMAIN2.(com|net|org)$" />
        </conditions>
    <action type="Redirect" url="http://www.MYDOMAIN.co.uk/{R:0}" />
</rule>

对于我的生活,我似乎无法将这些脚本合并到一个脚本中,该脚本将选择他的任何域并干净地将它们指向HTTPs .co.uk域的方向。

任何想法都会受到高度赞赏,因为正则表达不是我的强项。

亲切的问候

1 个答案:

答案 0 :(得分:0)

您只需按照必须处理的顺序添加两个规则(仅将最后一个规则设置为stopProcessing)。

  <rules>
    <clear />
    <rule name="domain redirect" stopProcessing="false">
      <match url="(.*)" />
      <conditions>
    <add input="{HTTP_HOST}" pattern="^(www.)?EXAMPLE2.(com|net)$" />
      </conditions>
      <action type="Redirect" url="http://www.EXAMPLE.net{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
    </rule>
    <rule name="HTTP to HTTPS redirect" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
    </rule>
  </rules>