Search code examples
c#http-redirectweb-configumbraco

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


I'm changing the URL format for a section of my website. all ##host##/blog/##article-name## will need become ##host##/news/##article-name##.

In Umbraco, I can redirect each individual page from within the CMS, but for efficiency, I'd like to set this particular redirect as a rule on a more permanent level.

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

When I run this it's redirecting to this URL ##host##/%5Enews/blog/##article-name##

Thanks in advance.


Solution

  • After a little bit of trial and error I have solved the issue. I hope this is helpful to somebody else. The issue was some unnecessary characters in my match query and redirect string.

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