Color theme Dark mode Font size Content width

Hugo aliases and redirects

Using aliases to prevent 404 when restructuring your Hugo site

Published on 01/6/2020

With the recent redesign and re-structuring of my website I decided to include year and month in URLs. I previously only used the post title as URL key, so a post with title Hello world would be available at With the new format this includes the section, year, and month, so for example

To prevent all old URLs from failing with a 404 I added aliases to all old posts. The documentation on aliases is pretty short and they’re a straight-forward, powerful tool to make content available under multiple URL paths. Just add an alias list to the front-matter of the post.

title: "My awesome post"
  - /my-awesome-post/
  - /2020-1/

The above would make the post available at,, and

Hugo creates a HTML page for each alias with the following content

<!DOCTYPE html>
    <link rel="canonical" href=""/>
    <meta name="robots" content="noindex">
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <meta http-equiv="refresh" content="0; url="/>

The line <meta http-equiv="refresh" content="0; url="/> refreshes the page after 0 seconds (immediately) and redirects to the new page at

With this little bit of extra work all old URLs should work and just redirect to the new pages.



Like this?

If this content has helped you or your company, consider making a donation to a good cause.

For example, consider donating to the following causes:

A Selfie of me

Kevin Gimbel

is a DevOps Engineer and avid (Video) Gamer. He’s also interested in Sci-Fi, Cyberpunk, and dystopian books.

Wearing a mask is a good idea!

You can find out more about me if you wish.