shou2017.com
JP

Redirecting Articles in Hugo

Sat Feb 10, 2018
Sat Aug 10, 2024

When I first created this blog with Hugo, I didn’t think I would keep it up for long, so I just gave random names to the articles in the post folder. However, I realized this was not ideal, so I decided to organize them into folders by year. I also decided to standardize the URL names. Below is the current state, and I will change it to something like 2018, 2017, etc.

Redirecting Articles in Hugo

What I want to achieve is to redirect https://shou2017.com/post/blog_cost201708/ to https://shou2017.com/post/2017/0908_blog_cost08/.

The official Hugo website provides detailed instructions on how to do this, so I used that as a reference.

TOML Front Matter

+++
aliases = [
    "/posts/my-original-url/",
    "/2010/01/01/even-earlier-url.html"
]
+++

YAML Front Matter

---
aliases:
    - /posts/my-original-url/
    - /2010/01/01/even-earlier-url.html
---

Example

List the old URLs in aliases and rename the .md file. I decided to standardize the format to year/month/day/filename, so I renamed it to 0908_blog_cost8.md.

---
title: "Server Costs for August 2017"
date:    2017-09-08T16:19:30+09:00
lastmod: 2024-08-10T16:48:51+09:00
draft: false
tags: []
categories: ["blog"]
aliases:
    - /post/blog_cost201708/ ← Old URL
# you can close something for this content if you open it in config.toml.
comment: false
toc: false
# reward: false
mathjax: false

# you can define another contentCopyright. e.g. contentCopyright: "This is another copyright."
# contentCopyright: false
---

Finally, delete all the contents of the S3 bucket and upload the new files. If you forget this step, the old URL articles will remain in S3, so don’t forget to delete them.

See Also