I’m in the process of adding redirect aliases to about 40 of my posts, and I’m curious if this can be done programmatically instead. All of the posts follow this format:
old URL: /blog/posts/this-post-url/
new URL: /blog/this-post-url/
My first thought was to use a partial, but since that references the front-matter, I don’t believe it will be able to help generate front-matter (or act in lieu of it). Of course, I’m happy to be proven wrong.
I didn’t see another way of creating redirects aside from aliases in the docs or a similar post to this question – but if those things exist, please let me know! Thanks for reading!
Bulk redirects can ben operated by your host. If you’re using Netlify you can generate the _redirects file they use through Hugo (and custom output formats) and therefor make it as dynamic as you like. We built a module that do just that:
Yes, I knew this was possible – I don’t know why I didn’t really consider it as an option. But your response prompted me to try it! I use firebase hosting, so to implement this all I did was add this to my firebase.json file: