Graphite Supports Redirects

13th October 2024

I've added support for page-level redirects to Graphite, the default theme that comes bundled with Ark, my static website generator.

This is a useful feature if you need to rename a page or move it to a new location — you can redirect the old page to the new location so old links will continue to work.

To redirect a page, add a redirect field to the node file's YAML header, e.g.

---
redirect: http://example.com/foo-bar/baz.html
---

To redirect a page to an @root/ URL, enclose the URL in double-quotes, e.g.

---
redirect: "@root/foo-bar/baz//"
---

The quotes are needed to stop the YAML parser treating the @ symbol as a "reserved indicator".

Because Ark is a static website generator, it can't support header-level HTTP redirects like 301 Moved Permanently. Instead, it adds a HTML redirect directive to the page's <head> element:

<meta http-equiv="refresh" content="0;url='http://example.com/'">

This makes web browsers immediately redirect the user to the new URL.