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
_redirectsfile. Next.js supports redirects in the config file.
The format of the file is:
/new-url /old-url statusThe status is optional and defaults to 302 (temporarily moved). I wanted this 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.