Enable content tree-based routing

Before you can start using content tree-based routing, the related feature needs to be enabled in the Xperience .NET application.

  1. Open your project in Visual Studio and edit the Program.cs file.

  2. Enable the content tree-based routing feature by calling UseWebPageRouting within AddKentico.

    C#
    Program.cs
    
    
    using Kentico.Content.Web.Mvc.Routing;
    using Kentico.Web.Mvc;
    
    ...
    
    WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
    
    ...
    
    builder.Services.AddKentico(features =>
    {
        // Enables content tree-based routing
        features.UseWebPageRouting();
    });
    
    

Content tree-based routing is now enabled for the application. The Kentico().MapRoutes() method called in your application’s startup pipeline registers a general route that matches URLs generated by the system for content types with the Include in routing option set.

Home page redirect and the website root URL

The home page is the page served when visitors access a website channel’s root URL (e.g., https://example.com/). Xperience handles the site root out of the box via the channel’s Home page setting. You don’t need custom routes or middleware to handle the site root – the Home page setting covers it.

To set the home page of a website channel:

  1. Edit your website channel in the Channel management application and switch to Channel settings.
  2. Under the Content tree-based routing section, enter the tree path of your desired home page into the Home page field.
    • To find the Tree path of a page, open the website channel’s application, select the page, and go to Properties → Information.
  3. Save the changes.

With the setting configured, the system:

  • Serves the specified page when the channel’s root URL is accessed. For languages other than the channel’s primary language, the root URL of the given language is used (e.g., https://example.com/es/).
  • Always uses the root URL as the canonical URL of the home page, and redirects the page’s other URLs to it. Using a unified home page URL is highly recommended because it prevents the duplicate content problem on your website’s most important URL.

If the Home page setting is empty, the channel’s root URL is inaccessible and visitors receive a 404 error. Keep this in mind when unpublishing or deleting the current home page – update the setting to point to the new home page.

Optional routing configuration

  1. Edit your website channel in the Channel management application and switch to Channel settings.
  2. Under the Content tree-based routing section:
    • Enable the Store edited URLs as former URLs setting if you want the system to keep track of changes made to page URLs and perform redirects from former to current URLs.
      • To prevent the accumulation of various temporary URLs as former URLs, we recommend enabling this setting only on live websites (i.e. production environments).
  3. Save the changes.