Redirects

Keep bookmarked and linked URLs working when you rename or move a page.

Before you begin

  • The new URL path decided before you change files, see Write → Where pages live for how file paths map to URLs
  • Preview running locally when you want to confirm the new page and redirect

For how redirects behave in production, branch previews, vanity subdomains, and custom domains, see Redirects. Field syntax lives in Page frontmatter.


When you change a published URL, update three things: the file at the new path, the sidebar entry, and a redirect stub at the old path.

Rename or move a page

  • Serve content from the new URL

    Rename or move the file under docs/ to match the new URL. For example, move docs/installation.mdx to docs/getting-started.mdx so the page serves at /getting-started.

  • Point sidebar at the new href

    Update the sidebar in docs.json so the entry points at the new href. Remove or replace the old path, readers should not land on a dead link from navigation. See Organize.

  • Keep bookmarks working with a redirect stub

    Create a redirect stub at the old file path (next section). Without it, bookmarks and external links to the old URL return 404 (which can negatively impact SEO rankings).

Add a redirect stub

Leave a minimal file at the old path and set redirect in frontmatter to the destination.

  • Keep a stub file at the old path

    Create or replace the file at the old location, for example docs/installation.mdx after you moved content to docs/getting-started.mdx.

  • Declare the destination in frontmatter

    Set redirect pointing at the new location:

    yaml
    ---
    redirect: /getting-started
    ---

    title and description are not required. The body can be empty. docs.page reads redirect and returns a 307 Temporary Redirect before any page content renders.

  • Resolve targets correctly across hosts

    Internal moves: use a root-relative path: /getting-started. No domain, no .mdx extension.

    External destinations: use a full URL starting with https://.

    Internal paths resolve against the same routing mode as the request (production, branch preview (~ref), vanity subdomain, or custom domain), so readers stay on the host and ref they started on. You do not need to hard-code https://docs.page/owner/repo for in-repo moves.

Forward deleted pages in bulk

Stubs work when you keep a file at the old path. When you delete pages outright — or need to forward many old URLs at once — add a centralized redirects map to docs.json instead of leaving a file behind for each one:

json
docs.json
"redirects": {
  "/installation": "/getting-started",
  "/old-api": "https://api.example.com/reference"
}

Keys are the old root-relative paths; values are internal paths or external https:// URLs. docs.page consults this map only when no file exists at the requested path, so it is the tool for URLs whose files were removed. Keep frontmatter stubs for the case where a file still lives at the old path.

See redirects and Redirects → The centralized redirects map.

Verify the redirect

After you add or change redirect stubs:

  • See the new page at its updated URL

    Open Preview and confirm the moved page renders at the new path. Confirm sidebar links point to the right href.

  • Confirm the old URL redirects in preview

    Open the old URL in the same preview session, for example /installation after you moved content to /getting-started. The browser should land on the new page without a 404.

  • Catch broken redirect targets before merge

    bash
    npx @docs.page/cli check

    The CLI scans frontmatter redirect targets the same way it validates internal links in page content. Fix any broken targets before you merge.

    For severity flags, monorepo paths, and CI setup, see CLI → Check documentation.

Troubleshooting

SymptomLikely causeFix
Old URL returns 404No stub file at the old path, or the stub was deletedRecreate the file at the old path with redirect in frontmatter
docs check reports a broken redirectTarget path does not match a page or asset in the repoUse the correct root-relative path (no .mdx). Confirm the destination file exists
Redirect sends readers to production from a branch previewUnlikely with internal paths, they resolve per request contextUse a root-relative path, not a hard-coded production URL. See Redirects
External redirect fails validationTypo in URL or unreachable hostFix the https:// target. Tune --external-links if CI flakes on third-party sites
Old page still appears in the sidebardocs.json still lists the old hrefUpdate or remove the sidebar entry in Organize

Related

  • Redirects: How per-page redirects work across routing modes, HTTP status, and limits.
  • Page frontmatter: Field reference for redirect and other per-page YAML options.
  • Organize: Point sidebar entries at the new URL after you move a page.
  • Preview: Confirm the new page and redirect locally.