【问题标题】:web.config redirect multiple domains to one AND redirect HTTP to HTTPsweb.config 将多个域重定向到一个并将 HTTP 重定向到 HTTPS
【发布时间】:2016-02-11 17:14:41
【问题描述】:

我正在使用 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>

这很好用。

我的客户希望我现在将大量其他非 HTTPs .com 域重定向到这个 HTTPs .co.uk 域。

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

<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 域的方向。

任何想法都将不胜感激,因为正则表达式不是我的强项。

亲切的问候

【问题讨论】:

    标签: redirect iis


    【解决方案1】:

    您可以简单地按照它们必须处理的顺序添加两条规则(只有最后一条规则设置为 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>
    

    【讨论】:

      猜你喜欢
      • 2013-04-01
      • 1970-01-01
      • 2016-01-30
      • 1970-01-01
      • 2018-01-13
      • 2016-09-03
      • 1970-01-01
      • 2015-05-19
      • 2017-12-01
      相关资源
      最近更新 更多