This is another post in my Umbraco Basics series. This post will tackle how to create a permanent redirect simply in Umbraco 9+
Umbraco is a great content management system. Most of the time it has the controls, APIs and system that a developer needs right there in the user-friendly interface. But other times, it can leave new developers confused.
For example, it always amazes me in this day and age that Umbraco doesn't have a built-in permanent redirect system, "but wait"... I hear you say, "There is one, right there under the content section"
![](/media/0h2fsdmr/image.png)
Indeed, this is a list of permanent redirects but only ones that Umbraco has created when you've renamed or moved a page. You can remove the redirect but there's no interface to create your own... This seems a little crazy because someone has taken the time to create this, a little bit of functionality to give you the ability to add your own would be great. But you can't.
In addition, you can download a third-party module to give you this facility, but I try to keep these things to a minimum as they can introduce bugs or security concerns or just not get updated when new versions of Umbraco are released.
So why do we need to implement 301 permanent redirects? A 301 permanent redirect is a way to inform search engines and browsers that a web page has moved permanently to a new location. It ensures that visitors and search engine crawlers are automatically redirected to the new URL, permanently, preserving SEO value and user experience.
So how do you do it? The answer is relatively simple as long as you have access to the code base and in particular the web.config file.
The web.config file is usually within the files created from a publish so take a look in the publish/compiled folder or on the web server root folder. Before you modify this file, please make sure that you make a backup of it.
The web.config file is a simple text file in xml format, to enter a rule for the permanent redirect you create a <rule> under <system.webServer> <rewrite> <rules>
The rule takes the form of a <match> and an <action>. It requires a RULENAME as shown below and if you have more than one rule in the file, then you must give them seperate names or you will get an error.
So, to the rule... If we previously had a page called
http://www.domain.com/blog/this-is-the-old-page and now you wanted to permanently redirect it to
http://www.domain.com/articles/this-is-the-new-url/
Then the rule in the web.config file would look like this:
<rule name="RULENAME" stopProcessing="true">
<match url="^/blog/this-is-the-old-page" ignoreCase="true" />
<action type="Redirect" url="/articles/this-is-the-new-url/" redirectType="Permanent" />
</rule>
For it to work within the web.config file, it needs to be in the correct place. There may already be a <system.webServer>, <rewrite> and <rules> sections, in which case add the rule code above just under the <rules> category as below.
If the above categories don't exist as tags in the web.config file then you will need to add them so it looks something like this. You can add multiple <rule> configurations to the <rules> section.
<system.webServer>
<rewrite>
<rules>
<rule name="RULENAME" stopProcessing="true">
<match url="^/blog/this-is-the-old-page" ignoreCase="true" />
<action type="Redirect" url="/articles/this-is-the-new-url/" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
Once you save the web.config overwriting the old one, the site should automatically see the difference in the configuration and recompile the site to run.
Once in place, simply go to the old URL and you should automatically be redirected to the new page! Simple.
If for some reason the redirection is not working, it could mean that your hosting company is actively stopping you making redirects or they have not configured the web server to perform redirects. If this is the case then you will need to contact your hosting company directly and ask them to configure the server for redirects.
So there we have it, permanent redirects in Umbraco without a third party module or delving into Microsoft Server configuration. Have fun!
Hey, I really could do with your help! If you find this article interesting, could you please do me a favour by either sharing it on your site or on social media. I would love to hear yours and other peoples' thoughts on this subject. And if this or any other content on the site has helped you and you would like to show your appreciation, then you can always
buy me a coffee ☕️ It would make the time I put into this more than worthwhile! Thank you 😃