简体   繁体   English

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

[英]web.config redirect multiple domains to one AND redirect HTTP to HTTPs

I am using web.config to redirect all HTTP traffic to a HTTPs website 我正在使用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>

This works just fine. 这样很好。

My client wants me to now redirect a whole load of other non HTTPs .com domains to this HTTPs .co.uk domain. 我的客户希望我现在将整个其他非HTTPs .com域的负载重定向到此HTTPs .co.uk域。

I found a redirect script: 我找到了重定向脚本:

<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>

For the life of me I cannot seem to combine these script into one script that will pick any of his domains and cleanly point them in the direction of the HTTPs .co.uk domain. 对于我来说,我似乎无法将这些脚本组合成一个脚本,该脚本可以选择他的任何域,并将它们明确指向HTTPs .co.uk域的方向。

Any ideas would be greatly appreciated as regular expressions are not my strong point. 因为正则表达式不是我的强项,所以任何想法都将不胜感激。

Kind Regards 亲切的问候

You can simply add two rules in the order they must process (with only the last rule set to stopProcessing). 您可以简单地按照必须处理的顺序添加两个规则(仅将最后一个规则设置为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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM