MVC Web.config 301 重定向包含一组 url 段的所有 url

MVC Web.config 301 redirect for all urls containing a set url segment

我正在更改我网站一部分的 URL 格式。所有 ##host##/blog/##article-name## will need become ##host##/news/##article-name##

在 Umbraco 中,我可以从 CMS 中重定向每个单独的页面,但为了提高效率,我想将这个特定的重定向设置为更永久级别的规则。

<rule name="Redirect from blog to news" enabled="true" stopProcessing="true">
   <match url="^blog/(.*)" />
   <action type="Redirect" url="^news/{R:0}" />
</rule>

当我 运行 这个它重定向到这个 URL ##host##/%5Enews/blog/##article-name##

提前致谢。

经过反复试验,我已经解决了这个问题。我希望这对其他人有帮助。问题是我的匹配查询和重定向字符串中有一些不必要的字符。

<rule name="Redirect from blog to news" enabled="true" stopProcessing="true">
    <match url="^blog(.*)" />
    <action type="Redirect" url="news{R:1}" />
</rule>