Home Writing Reading

til / _redirects in Cloudflare Pages

Cloudflare Pages has support for creating redirects using a _redirects file. This was exactly what I needed to create short URLs for my TIL posts. It won’t be a permanent solution, as a project is limited to 100 redirects. We’ll see what happens when I reach that amount.

Netlify also supports using a _redirects file. Next.js supports redirects in the config file.

The format of the file is:

/new-url /old-url http-status

The http-status is optional and defaults to 302 (temporarily moved). I wanted the following format for my TILs and to use 301 (permanently moved):

/til/1 /posts/testing-rescript-at-hemnet/ 301

I generate the TILs from files in my Obsidian vault, so when I update the posts, the redirects file gets updated as well. You can now reach this post by using /til/43.

Since I wrote this post, I’ve migrated to Remix where I could easily create this redirect behavior: willcodefor.beer is now a Remix app.


  • Loading next post...
  • Loading previous post...