求助: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.comwith your actual target third-party URL.
Quick Tips for Sitecore/ASP.NET MVC
- Place these rules in your site’s
web.configunder<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

