使用 WebConfig 重定向重定向到包含 match-url 的 URL 会导致循环

Using a WebConfig redirect to redirect to a URL that contains the match-url causes loop

所以我有一个 url 已经更新了。为了保留旧的 url 我想将它重定向到新的以防它仍在使用中。 我的 web.config:

中有这样的代码

<rule name="Redirect" enabled="true" stopProcessing="true">
    <match url="^old/url" ignoreCase="true" />
    <action type="Redirect" url="/old/url/new"/>
</rule>

但由于“/old/url/new”包含“^old/url”,它会导致“重定向过多”错误。新的 url 仍然像以前的那样匹配。

有没有办法结束比赛URL?就像一个通配符,除了 nothing 可以跟在它后面。或者我可以添加一个 属性 来防止这个问题?

我把它放在括号中并在末尾添加一个 $ 来修复它,就像这样

<match url="^(old/url)$" ignoreCase="true" />