Maximizing Your Kentico Site’s UX With Fallback Redirects

Fallback redirects can ensure visitors are always directed to the correct pages, even if the original URL is no longer valid. This article shares the benefits of custom fallback redirects and provides best practices for implementing them on your Kentico website.

In the fast-paced world of website management, changes are inevitable. Pages may move or be removed, and links can become outdated, leading to frustrating 404 errors for visitors and negatively impacting search engine rankings. That’s where fallback redirects come in. By using these redirects, you can ensure that visitors are always directed to the correct pages, even if the original URL is no longer valid. This creates a more ideal user experience, helps maintain search engine rankings, and keeps your Kentico website running smoothly. In this article, we’ll explore the benefits of custom fallback redirects and provide best practices for implementing them on your website.

Proactive Strategies for Moving, Changing, and Deleting Website Content

Having a fallback redirect can be a lifesaver for websites with frequently changing or moving content. Imagine a well-maintained structure that guides visitors to their desired destination, with a news landing page to help them navigate to individual news nodes. But what happens when a news article is archived, and the page can’t be found? It would be helpful to have a fallback redirect. With this tool, you can ensure a flawless user experience by routing visitors back to the news landing page, even when content disappears. Using a fallback redirect will provide a better user experience that will keep visitors coming back for more.

If you’re managing a website with blogs that use a structure like site/blogs/(document-name), a site restructuring or migration can pose a challenge. For example, without a landing page for blogs on the new site, visitors may encounter 404 errors when trying to access a blog that has been moved or removed. By implementing a fallback routing for blogs, you can ensure that visitors will be seamlessly routed to the news landing page when they try to access a blog affected by the restructuring.

Best Practices for Time-Based Content Management and Automatic Archiving

In addition to scenarios where content is frequently changing or moving, there are also cases where content needs to be removed from a website because it is time-sensitive, such as events that have passed or promotions that have ended. Automatic archiving can be a useful tool in this situation, as it can move content no longer relevant to a separate archive rather than deleting it altogether. However, even with automatic archiving in place, visitors may still try to access this content after it has been moved, resulting in 404 errors. Search engines may also be led astray by URLs that have been moved or deleted. By using a fallback redirect, you can ensure that visitors are routed to an appropriate page, such as an archived events page or a promotions archive, when they try to access content that has been removed due to time sensitivity. This will also preserve a consistent user experience and search engine rankings, even during a website cleanup.

Creating Custom Redirects for a Seamless User Experience

Redirects play a critical role in website maintenance, ensuring a seamless user experience when content changes or moves. But how do you create these redirects, and where should they be stored? To maintain a clean and organized project, redirects should be added to a new class in a location for extensions. This allows for easy management and ensures a consistent naming convention. Then, when a 404 error occurs, the URL is checked against these rules to determine if a redirect should be triggered. It’s like having a virtual gatekeeper for your website, ensuring that visitors always find the right content. Proper implementation of redirects can help prevent frustration for visitors and ensure that your website remains user-friendly. Following best practices for creating and checking redirects, you can become an expert in website maintenance and optimization. Below is an example of a redirect extension to ensure that child pages are redirected to the landing page in the case of a 404 error.

Custom Redirect Code Snippet:
				
					public static class CustomRedirectExtension
{
    	/// <summary> Adds a redirect for Detail pages to redirect to the Landing</summary>
    	public static IApplicationBuilder UseCustomLandingRedirect( this IApplicationBuilder app )
    	{
        	if( app == null )
        	{
            	throw new ArgumentNullException( nameof( app ) );
        	}
 
        	return app.UseStatusCodePages(
            	async context =>
            	{
                    await Task.Run( ( ) =>
                	{
                        var originalPath = context.HttpContext.Request.Path;
                        var originalQueryString = context.HttpContext.Request.QueryString;
 
                        if( IsChildPage( originalPath ) )
                        {
 	                       context.HttpContext.Response.Redirect( GetLandingUrl( context ) );
                        }
                	} );
            	}
        	);
    	}
 
    	private static bool IsChildPage( PathString path )
        	=> path.StartsWithSegments( "/news", StringComparison.OrdinalIgnoreCase )
        	|| path.StartsWithSegments( "/blogs", StringComparison.OrdinalIgnoreCase );
 
    	private static string GetLandingUrl( StatusCodeContext context )
    	{
        	var landingNode = DocumentHelper
                .GetDocuments<LandingNode>()
                .Published()
          	.TopN( 1 )
                .FirstOrDefault();
 
        	var relativeUrl = DocumentURLProvider.GetUrlForCulture( landingNode, LocalizationContext.CurrentCulture.CultureCode );
 
        	var currentUrl = context.HttpContext.Request.GetDisplayUrl();
        	var uriBuilder = new UriBuilder( currentUrl );
            uriBuilder.Path = relativeUrl.TrimStart( '~' );
 
            return uriBuilder.ToString();
    	}
}


				
			

Integrating Custom Redirects into Your Startup Configuration

To use the custom redirect rules, they must be added to the Configure method in Startup.cs (or the app section, depending on the version of .NET). This is done by calling the appropriate method within the IApplicationBuilder, such as app.UseCustomLandingRedirects(). Including the code below in your startup configuration ensures that your website directs visitors to the right content, even when pages are moved or deleted. This helps to maintain a positive user experience on your website.

Adding the redirects to be used in the application:
				
					public void Configure( IApplicationBuilder app )
    	{
            ...
        	app. UseCustomLandingRedirects ();
            ...
    	}
				
			

Transforming User Experience: The Key Benefits of This Implementation

Once the custom redirect rules have been implemented, site visitors and search engines will always be redirected to the correct pages, even if the original URL is no longer valid. It’s also possible to create new custom redirect classes and add them to the startup configuration to fall back to multiple URLs. In addition, by changing the page type retrieved, you can specify which page visitors should be directed to in the case of a 404 error. This allows for greater flexibility and control over your website’s content and navigation.

One of the great things about custom redirects is their flexibility. You can create as many fallback redirects as needed to ensure visitors always find what they’re looking for. Whether you’re handling news articles, blog posts, event pages, or other types of content, custom redirects ensure that visitors are always directed to the appropriate landing page. By taking a comprehensive approach to custom redirects and customizing them to meet your specific needs, you can create a highly effective website maintenance strategy that keeps your visitors engaged and satisfied. Additionally, by following the best practices outlined in this article and staying on top of changes to your website’s structure and content, you can ensure that your custom redirects continue to provide value and enhance the user experience over time.

The Power of Custom Redirects for Maintaining a Seamless User Experience

By taking advantage of custom redirects, website owners and developers can ensure that visitors always find the content they’re looking for, even if a page has been moved, deleted, or archived. Creating custom redirects may require some effort upfront, but the benefits of user satisfaction and search engine optimization can be significant. In addition, by following the best practices outlined in this article, such as identifying the need for redirects, creating and checking redirect rules, and adding them to the startup configuration, you can become an expert in website maintenance and optimization. Ultimately, custom redirects are a powerful tool that can help you keep your website running smoothly and keep visitors engaged and satisfied.

Your Kentico Experts

Whether your team is looking to upgrade an existing site, tackle a complex integration, or start from scratch, our team of 35+ highly-skilled developers, designers, and digital strategists, including a Kentico MVP, has the expertise to take your brand from strategy to launch. As a Kentico Gold Partner for over 10 years, we bring a wealth of experience and proven success to every project we undertake. Send us a message to get started!

About the Author

Brandon Dekker

When Brandon was offered a position at BizStream, he almost couldn’t believe it! He gets to do what he loves daily in a fun environment – this is his dream job! In his free time, he hangs out with his Destiny 2 clan, writes more code, and works on cars.

Subscribe to Our Blog

Stay up to date on what BizStream is doing and keep in the loop on the latest in marketing & technology.