Rift Logo RiftJS

Error Pages

Rift supports custom error page generation so that you can gracefully handle broken links, missing content, or unexpected conditions in your static site. Since Rift is a static-first framework, error pages are pre-rendered like any other page and served by your hosting provider in response to 404 or 500-type errors.

What is an Error Page?

An error page is a fallback route that is shown when no other content matches a given path. The most common is a 404 Not Found page, which appears when the user visits a URL that doesn’t map to any controller or generated page.

Creating a 404 Page

To add a basic 404 page to your site, simply create a file at:

src/site/404.njk

This file is treated like any other page — it can include frontmatter, a layout reference, and even dynamic logic using Nunjucks or your templating language of choice.

Localization Support

If your site uses multiple locales, you can define localized 404 pages using the same i18n strategy used for content pages. For example:

src/site/en/404.njk
src/site/fr/404.njk

Previewing Error Pages Locally

When running Rift in development mode, unmatched routes will serve your 404 page automatically (if defined). This helps you test error UX during development. You can also directly navigate to /404.html in your browser to preview the page.

Hosting Considerations

Static hosting providers typically serve a file named 404.html when a request does not match any known file path. Rift’s job is to generate that file. Your hosting platform then handles routing errors to that output.

Rendering Logic

Rift does not treat error pages as special in terms of how they are built. The 404 page is just a page with a specific permalink (404.html) and optional layout or controller logic. This means you can:

  • Use partials, components, or Nunjucks includes
  • Include localized content from collections
  • Display fallback search or sitemap suggestions
  • Make it match your site’s overall design exactly

Summary

  • Create src/site/404.html or 404.njk to define a custom not-found page
  • Must use permalink: 404.html so your host recognizes it
  • Can use layouts, collections, or localization like any other page
  • Supports multi-locale if you're generating localized outputs
  • Works seamlessly with most static hosts