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

求助:IIS URL Rewrite规则配置——域名合并后的301重定向需求

Hey there! Let's tackle these IIS URL Rewrite rules for your Sitecore/ASP.NET MVC site—since rewrite rules are processed top-to-bottom, we’ll start with the most specific rules first to avoid unintended matches. Here’s how to configure each requirement:

Rule 1: One-to-one mapping for www.xyz.com/test → www.abc.com/test1

This is the narrowest rule, so it needs to come first to prevent being overridden by broader ones. It targets exactly the /test path (with or without a trailing slash) on www.xyz.com and redirects to the corresponding path on www.abc.com.

<rule name="XYZ Test to ABC Test1" stopProcessing="true">
  <match url="^test/?$" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^www\.xyz\.com$" />
  </conditions>
  <action type="Redirect" url="https://www.abc.com/test1" redirectType="Permanent" />
</rule>
  • stopProcessing="true" ensures no other rules run once this one matches.
  • redirectType="Permanent" sends a 301 redirect, which is ideal for preserving SEO value.

Rule 2: Redirect all non-homepage inner pages to www.abc.com/foo

Next, we’ll target every inner page on www.xyz.com except the homepage and the /test path we already handled. We’ll add conditions to exclude these cases to avoid conflicts.

<rule name="XYZ Inner Pages to ABC Foo" stopProcessing="true">
  <match url=".*" />
  <conditions logicalGrouping="MatchAll">
    <add input="{HTTP_HOST}" pattern="^www\.xyz\.com$" />
    <add input="{REQUEST_URI}" pattern="^/$" negate="true" /> <!-- Skip homepage -->
    <add input="{REQUEST_URI}" pattern="^/test/?$" negate="true" /> <!-- Skip the path from Rule 1 -->
  </conditions>
  <action type="Redirect" url="https://www.abc.com/foo" redirectType="Permanent" />
</rule>
  • negate="true" tells the rule to ignore matches for the specified patterns.
  • The .* match URL catches any path that isn’t excluded by the conditions.

Rule 3: Redirect XYZ homepage to third-party URL

Finally, we’ll handle the homepage redirect. This rule only triggers when the request is for the root of www.xyz.com.

<rule name="XYZ Homepage to Third-Party" stopProcessing="true">
  <match url="^$" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^www\.xyz\.com$" />
  </conditions>
  <action type="Redirect" url="https://your-third-party-url-here.com" redirectType="Permanent" />
</rule>
  • Replace https://your-third-party-url-here.com with your actual target third-party URL.

Quick Tips for Sitecore/ASP.NET MVC

  • Place these rules in your site’s web.config under <system.webServer> → <rewrite> → <rules>, before any Sitecore-specific rewrite rules (like those for Sitecore’s routing) to ensure they’re processed first.
  • Test each rule using IIS’s built-in URL Rewrite Test Tool (right-click the rule in IIS Manager → "Test Pattern") to verify matches work as expected.
  • Stick with Permanent (301) redirects unless you need temporary ones—301s help maintain SEO ranking for your old URLs.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 08:27:15