【问题标题】:IIS Rewrite Rule - Redirect from one domain binding to another domain bindingIIS 重写规则 - 从一个域绑定重定向到另一个域绑定
【发布时间】:2017-05-06 15:55:15
【问题描述】:

我的 IIS 站点上有多个绑定,我想捕获所有对

的请求

以下任何一项 - domainA.co.uk、www.domainA.co.uk、domainA.com、www.domainA.com

并重定向到站点上其他绑定之一上的页面

www.domainB.com/my-folder/

这可以通过 URL 重写实现吗?

【问题讨论】:

    标签: iis url-rewriting url-rewrite-module


    【解决方案1】:

    url重写是可能的,你需要使用这个规则:

    <rule name="all domains to www.domainB.com/my-folder" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAny">
            <add input="{HTTP_HOST}" pattern="^domainA.co.uk$" ignoreCase="true" />
            <add input="{HTTP_HOST}" pattern="^www.domainA.co.uk$" ignoreCase="true" />
            <add input="{HTTP_HOST}" pattern="^domainA.com$" ignoreCase="true" />
            <add input="{HTTP_HOST}" pattern="^www.domainA.com$" ignoreCase="true" />
        </conditions>
        <action type="Redirect" url="http://www.domainB.com/my-folder/{R:1}" />
    </rule>
    

    它将重定向网址:

    • domainA.co.ukwww.domainB.com/my-folder/
    • www.domainA.co.ukwww.domainB.com/my-folder/
    • domainA.comwww.domainB.com/my-folder/
    • www.domainA.comwww.domainB.com/my-folder/
    • www.domainA.com/somethingwww.domainB.com/my-folder/something (如果你不想这样,只需删除 {R:1} 表单规则)

    【讨论】:

    • 想补充一下,这条规则显然会进入&lt;system.webServer&gt;标签下的&lt;rewrite&gt; &lt;rules&gt;标签。
    【解决方案2】:

    您可以使用重写来重定向域

    <rewrite>
          <rules>
            <rule name="Force non-WWW and SSL" enabled="true" stopProcessing="true">
              <match url="(.*)" />
              <conditions logicalGrouping="MatchAll">
    
                <add input="{HTTP_HOST}" negate="true" pattern="^www.(.*)$" ignoreCase="true" />
              </conditions>
              <action type="Redirect" url="https://www.{C:1}/{R:1}" appendQueryString="true" redirectType="Permanent" />
            </rule>
          </rules>
        </rewrite>     
    

    【讨论】:

      猜你喜欢
      • 2013-08-04
      • 2020-10-01
      • 2011-06-29
      • 1970-01-01
      • 2018-07-28
      • 1970-01-01
      • 2013-05-18
      • 2015-08-20
      • 2017-08-21
      相关资源
      最近更新 更多