You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在IIS的web.config现有重定向规则中添加旧域名转新域名重定向?

修正旧域名跳转规则的方案

你的旧规则失效的核心问题有三个:

  • 错误地用<match url>匹配域名,而url节点对应的是域名之后的路径部分,不是域名本身;
  • 未设置stopProcessing="true",导致后续规则会继续执行,打乱跳转逻辑;
  • 没覆盖带www前缀的旧域名请求(比如www.olddomain.com/xxx)。

修正后的规则代码

把以下规则放在「Redirect to https」规则之后、「Redirect - Top domains with non-www to www」规则之前:

<rule name="Old to new domain" enabled="true" stopProcessing="true">
    <match url="*" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="^olddomain\.com$" />
        <add input="{HTTP_HOST}" pattern="^www\.olddomain\.com$" />
    </conditions>
    <action type="Redirect" url="https://www.newdomain.com" redirectType="Permanent" />
</rule>

规则说明

  1. 匹配所有路径:<match url="*" 会捕获旧域名下的任意请求路径(不管是根目录还是/whatever);
  2. 覆盖所有旧域名变体:通过{HTTP_HOST}条件匹配olddomain.com和www.olddomain.com两种域名形式;
  3. 终止后续规则:stopProcessing="true"确保完成跳转后不再执行后面的www前缀、尾斜杠规则;
  4. 301永久重定向:redirectType="Permanent"是搜索引擎友好的重定向类型,可传递权重。

最终规则顺序

调整后的完整规则顺序应该是:

  1. Redirect to https
  2. Old to new domain(新增的修正规则)
  3. Redirect - Top domains with non-www to www
  4. Add trailing slash

内容的提问来源于stack exchange,提问作者Dan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 11:05:09