IIS 10多参数URL重定向配置出现500内部服务器错误的技术咨询
Hey Max, let's break down what's causing that 500 internal server error and get your redirect working with all those query parameters.
The Root Cause
Your current config has two conflicting redirect mechanisms enabled at the same time: the IIS Rewrite module rule and the <httpRedirect> element. When both try to handle the same request, IIS gets confused and throws a 500 error. Additionally, your rewrite rule has a syntax mismatch that might be compounding the issue.
The Correct Configuration
Remove the <httpRedirect> block entirely, and adjust your rewrite rule to target only your source domain and properly match all request paths. Here's the fixed web.config:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <clear /> <rule name="Redirect subdomain.example.com to target URL" enabled="true" stopProcessing="true"> <match url=".*" /> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> <add input="{HTTP_HOST}" pattern="^subdomain\.example\.com$" /> </conditions> <action type="Redirect" url="https://target.com/com/en/products-z/xxx/yyy/wow-fan.html?utm_source=oldvanity&utm_medium=redirect&utm_campaign=oldvanity" appendQueryString="false" redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
Key Changes Explained
- Removed
<httpRedirect>: This eliminates the conflict between two redirect systems. The Rewrite module alone is sufficient for this task. - Fixed URL matching: Changed
patternSyntax="ExactMatch"(which was incompatible with(.*)) to use the default ECMAScript pattern matching withmatch url=".*"—this correctly captures all paths under your subdomain. - Added domain targeting: The
<add input="{HTTP_HOST}" pattern="^subdomain\.example\.com$"condition ensures only requests to your specific source domain are redirected, preventing unintended effects on other sites hosted on the same IIS server. - Valid query parameter escaping: Your use of
&for ampersands is already correct for XML—this wasn't the issue, so we kept it as-is.
Why Your Previous Fixes Didn't Work
- Adding
$Q$Ahad no effect because you setappendQueryString="false", which tells IIS not to append any original query parameters to the target URL. - The single-parameter URL worked by coincidence, but the underlying conflict between redirect mechanisms was still present—it just didn't trigger the 500 error in that specific case.
Test this config, and your redirect should work smoothly with all three utm parameters now!
内容的提问来源于stack exchange,提问作者Moaxl

