Brandon Rozek

Photo of Brandon Rozek

PhD Student @ RPI studying Automated Reasoning in AI and Linux Enthusiast.

Preserving Classic URLs on my Website

Published on

Updated on

2 minute reading time

Warning: This post has not been modified for over 2 years. For technical posts, make sure that it is still relevant.

At some point in 2018 I switched my website from using Wordpress on the backend to Hugo. I used a simple script to migrate everything over and in that migration a few things broke.

  • Code snippets do not show up
  • Images don’t show up
  • URLs are different

I’ve gone back through some of my old posts and fixed up the code snippets. I usually decide to go back when I see sufficient traffic to one of those older pages.

I recently discovered that Hugo supported aliases. This will allow me to setup redirect at the old URLs that my blog posts used to be in. I can do this by adding a small snippet to my front YAML.

    - /2018/06/05/old/url/here

This will then redirect https://brandonrozek.com/2018/06/05/old/url/here to the current URL of the post I’m editing.

When I discovered this, I went ahead and redirected all my old URL blog posts to their current day versions. It makes me happy that I’m lowering the amount of link rot that I’m contributing to the web.

How does it do this? It creates a simple webpage that contains a HTTP-Equiv tag which tells the browser to redirect it. Directly from the Hugo documentation:

<!DOCTYPE html>
    <link rel="canonical" href="https://example.com/posts/my-intended-url"/>
    <meta name="robots" content="noindex">
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <meta http-equiv="refresh" content="0; url=https://example.com/posts/my-intended-url"/>
Reply via Email Buy me a Coffee
Was this useful? Feel free to share: Hacker News Reddit Twitter

Published a response to this? :