---
title: Enable content tree-based routing
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

Before you can start using [content tree-based routing](https://docs.kentico.com/documentation/developers-and-admins/development/routing/content-tree-based-routing.md), 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](https://docs.kentico.com/documentation/developers-and-admins/development/website-development-basics/configure-new-projects/enable-application-features.md) the content tree-based routing feature by calling `UseWebPageRouting` within `AddKentico`.

   ```csharp title="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](https://docs.kentico.com/documentation/developers-and-admins/development/content-types.md) 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](https://docs.kentico.com/documentation/developers-and-admins/configuration/website-channel-management.md) 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](https://docs.kentico.com/documentation/developers-and-admins/configuration/languages.md) 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](https://docs.kentico.com/documentation/business-users/website-content/manage-page-urls.md#select-the-canonical-url-of-pages) 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.

> **Warning:** 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](https://docs.kentico.com/documentation/business-users/website-content/edit-and-publish-pages.md#unpublishing-or-deleting-the-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](https://docs.kentico.com/documentation/business-users/website-content/manage-page-urls.md) 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.
