#How to add a custom URL to a page on starlight.

3 messages · Page 1 of 1 (latest)

thin crater
#

I have an astro starlight page and want the URL path of a specific project page to be simplified so that it contains a shorter version of the title instead of the full version. How can i do this?

hollow solsticeBOT
#

Hi @thin crater. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

To customize the URL path (slug) of a page in Astro Starlight, you can use the slug frontmatter property in your Markdown or MDX file. This allows you to override the default URL generated from the file name and set a custom, shorter path for your page.

For example, if your file is named my-long-project-title.md but you want the URL to be /project, add the following to the top of your file:

---
title: My Long Project Title
slug: project
---
Page content goes here.

This will generate the page at /project instead of /my-long-project-title or any nested path based on the file name. The slug property is specifically designed for this use case and is documented in the Starlight frontmatter reference Frontmatter Reference.

If you need more advanced control (such as dynamic or programmatic slugs), you may need to use Astro’s file-based routing in src/pages/, but for most Starlight content pages, setting the slug in frontmatter is the recommended approach.

Note: The slug property is only available for Markdown/MDX content pages, not for custom .astro pages in src/pages/ Frontmatter Reference.


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: