【问题标题】:IIS URL Rewrite Domain change 301 redirect individually only some pages and all other pages to another URLIIS URL 重写域更改 301 仅将某些页面和所有其他页面单独重定向到另一个 URL
【发布时间】:2018-02-15 17:40:40
【问题描述】:

我是 IIS URL 重写规则 Regex 的新手,在这里寻求帮助。

这是一个使用 ASP.NET MVC 构建的 sitecore 网站。我有一个域,即 www.xyz.com 与另一个域合并,即 www.abc.com 。我有 www.xyz.com/test -> www.abc.com/test1 的一对一映射。 www.xyz.com/xx 的所有内部页面都将与 www.abc.com/foo 映射,除了 www.xyz.com 的主页

  • 我目前被困在我该怎么做, 1) 将 www.xyz.com/ 主页重定向到第三方 URL? 2)同时保持www.xyz.com/internal pages与www.abc.com/internal pages的1-1映射

我正在使用 IIS URL 重写规则将 www.xyz.com 的域重定向到 www.abc.com,并在使用第三方页面重定向主页时寻求更多帮助

提前致谢!

【问题讨论】:

    标签: asp.net asp.net-mvc iis-7 url-redirection


    【解决方案1】:

    您只需要两个不同的重定向规则,第一个规则将检查根域并重定向到第三方 url,第二个规则将检查内部页面并重定向到新域上的内部页面

    它看起来像这样

        <rule name="redirect root to third party" stopProcessing="true">
             <match url="^$" ignoreCase="true" />
             <conditions logicalGrouping="MatchAll">
                <add input="{HTTP_HOST}" pattern="(www.)?xyz\.com$" />
             </conditions>
             <action type="Redirect" redirectType="Permanent" url="<third party url here>" />
        </rule>
        <rule name="redirect to new domain" stopProcessing="true">
             <match url="/(.*)" />
             <conditions>
                   <add input="{HTTP_HOST}" pattern="^(www.)?xyz\.com$" />
             </conditions>
             <action type="Redirect" url="http://<new domain>/{R:1}" redirectType="Permanent" />
        </rule>
    

    P.S:在第二条规则中,请检查 /——我自己没有测试过规则,可能在目标 url 中引入了额外的斜杠或删除了斜杠,无论是什么你都可以修复它。这里的要点是您需要两个单独的规则,一个用于检查确切的域,之后没有任何内容并重定向到第三方,另一个用于子页面重定向的规则

    【讨论】:

      猜你喜欢
      • 2013-04-20
      • 1970-01-01
      • 2021-12-24
      • 2011-04-26
      • 2021-04-10
      • 2023-02-02
      • 1970-01-01
      • 2017-09-09
      • 2015-08-14
      相关资源
      最近更新 更多