【问题标题】:IIS 7 redirect 301 domain A to domain BIIS 7 将 301 域 A 重定向到域 B
【发布时间】:2017-03-23 03:53:28
【问题描述】:

如何在 IIS7 中重定向(301)? 我正在尝试使用 web.config 中的重写规则将链接表单“domainA.com/link_A”重定向到“domainB.com/link_B”。如何对选定的链接执行此操作? 对吗?

    <rule name="redirect" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domainA.com/link_A$ />
</conditions>
<action type="Redirect" url="http://www.domainB.com/link_B{R:0}" redirectType="Permanent" />
</rule>

【问题讨论】:

    标签: redirect mod-rewrite iis web-config


    【解决方案1】:

    您需要将“link_A”部分移至 URL,因为 HTTP_HOST 仅匹配域名。所以你的规则应该是这样的

    <rule name="rewriting" stopProcessing="true">
       <match url="link_A" />
       <conditions>
          <add input="{HTTP_HOST}" pattern="^domainA.com$" />
       </conditions>
       <action type="Redirect" url="http://www.domainB.com/link_B{R:0}" redirectType="Permanent" />
    </rule>
    

    【讨论】:

    • 感谢您的回答。我想知道重写〜400个链接的最佳方法是什么。我应该在 web.config 中使用 400 次此代码,还是使用更优化的方式来执行此操作?
    • 如果 DomainA 和 DomainB 上的链接之间存在某种模式,您可以在重定向 URL 中使用规则变量。实际上,我在使用它的答案中犯了一个小错误。它实际上会重定向到 www.domainB.com/link_Blink_A,而不是重定向到 www.domainB.com/link_B,因为 {R:0} 部分会在重定向 URL 中插入匹配的 URL。
    • 答案被接受后为什么不接受?
    猜你喜欢
    • 2018-08-31
    • 1970-01-01
    • 1970-01-01
    • 2013-02-02
    • 2013-10-19
    • 2016-01-24
    • 1970-01-01
    • 1970-01-01
    • 2011-07-08
    相关资源
    最近更新 更多