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

使用IIS Rewrite配置动态URL重写时的500.50报错修复咨询

修复方案

问题根源

你遇到的500.50错误,核心原因有两个:一是捕获组引用错误——{R:1}对应<match>标签里的正则捕获组,但你的捕获规则写在<conditions>中,这里得用{C:1}来引用;二是原正则仅匹配带/something的路径,不满足something可选的需求。

修正后的配置(两种可选方式)

方式一:直接在中定义规则(更简洁)

<rule name="Product Route Rewrite" stopProcessing="true">
  <match url="^product/(\d+)(/.*)?$" />
  <action type="Rewrite" url="product/{R:1}.html" />
</rule>
  • 正则^product/(\d+)(/.*)?$说明:
    • (\d+)负责捕获产品ID;
    • (/.*)?表示/something部分为可选,同时匹配/product/1和/product/1/something两种路径;
  • 这里用{R:1}是因为捕获组来自<match>的正则,符合IIS Rewrite的引用规则。

方式二:保留的写法

<rule name="ReactRouter Routes" stopProcessing="true">
  <match url=".*" />
  <conditions logicalGrouping="MatchAll">
    <add input="{PATH_INFO}" pattern="^/product/(\d+)(/.*)?$" />
  </conditions>
  <action type="Rewrite" url="product/{C:1}.html" />
</rule>
  • 把原正则\/product\/(\d+)\/.*改为^/product/(\d+)(/.*)?$,实现something可选的匹配;
  • 用{C:1}替代{R:1},正确引用<conditions>中捕获的产品ID。

验证

配置生效后,访问http://localhost:8085/product/1或http://localhost:8085/product/1/something,都会被重写为http://localhost:8085/product/1.html。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 10:33:47