When building a web app, you need to decide what your URLs are going to look like. Do you need hierarchical URLs or short URLs? Do you need the URLs to be human-readable? Let's look at several options you can choose from.
Content model ≠ URL structure
Keep in mind that your content model doesn’t need to reflect your URL structure. In fact, it shouldn't. Kontent.ai gives you enough flexibility to create any hierarchy you want. The URL hierarchy is just one of the relationships in a content model.Your web app, however, doesn’t need to expose that hierarchy. For example, you can nest your content four levels deep while enjoying nice short URLs.
Your options for URL structure
There are two well-established approaches to choose from.
Traditional hierarchical URLs such as /section/subsection/topic/page
Short URLs such as /blog/page
Your choice depends on your requirements and preference. The choice also determines how you split your URLs and how complex your routing might get.
Hierarchical URLs for large amounts of content
Hierarchical URLs look like /section/subsection/topic/page. These URLs show you the page location in the context of the whole website. You might want to use hierarchical URLs for projects with lots of content organized into categories or topics.For example, this applies to knowledge bases, documentation portals, or help centers. If you use any kind of web analytics, this approach lets you see how specific topics covered on your website perform. All you need to do is filter the URLs by the topic mentioned in them, for instance.
How to build hierarchical URLs
Hierarchical URLs consist of several levels depending on how nested your content is. For example, this page is on the third level. Each part of the URL (separated by the slash symbol /) relates to a specific level in the hierarchy.In your Kontent.ai project, you can have content items linked together to represent your nested hierarchy. Each linked content item defines a URL slug, which you add together to form the URLs.To build hierarchical URLs for your pages, you need to retrieve the content items from your project and go through the hierarchy in your app from top to bottom (following the content of the linked items elements). This gives you a list of URLs that you can match with specific content items.
Short URLs
Short URLs are one or two levels deep. If you don’t need hierarchical URLs, you can use shorter URLs like /campaigns/autumn-flash-sale or /whats-ahead-for-us. They give you human-readable text that’s often fully visible in the address bar.You might want to use short URLs for product websites, e-commerce shops, or blogs. You can also use single-level URLs like /about-us for single-purpose websites or microsites.
How to build short URLs
Consider the URL /campaigns/autumn-flash-sale for a marketing campaign page. The URL is two levels deep – one level is the section identifier /campaigns and the second level is the URL slug of the specific page.You can have more sections for different types of content like articles or events. For each type, you create its own section (like /articles or /events), and its own route within your app.To build short URLs, retrieve the content items of a specific type first and then use their URL slug value for the URL. If you have lots of content with possibly duplicate titles, consider adding another identifier in the URL next to the URL slug to make sure your URLs are unique.
Keep your URLs unique
When you're creating routing logic in your app, you need to decide how to identify your content in the URLs.While using URL slugs as identifiers is a good starting point, keep in mind that URL slugs aren't guaranteed to be unique across your project. However, they will likely be unique for specific content items such as articles.The chance of running into naming conflicts is also lower with hierarchical URLs than with shorter URLs.
Sign in with your Kontent.ai credentials or sign up for free to unlock the full lesson, track your progress, and access exclusive expert insights and tips!