I still don't get Aliasses

Really. It’s been like 6 months or 8 I’m using HUGO and I could never make those work.

This is what I do:

# /content/some-page/hello.md
----
Title: "Some Page Hello"
Weight: "1"
aliases: "/contact-here/"
----
# /content/contact-here/index.md
---
Title: "Contact Here"
Weight: "1"
---

What I assume is: when I get to some-page/hello/ I will be redirected to contact-here, but it ain’t happening.

Halp

How Hugo Aliases Work Docs.

Given

# /content/some-page/hello.md
----
Title: "Some Page Hello"
Weight: "1"
aliases: "/contact-here/"
----

If you navigate to /contact-here/ you will get redirected to /some-page/hello/.

public/contact-here/ will contain:

<!DOCTYPE html>
<html>

  <head>
    <title>https://example.com/some-page/hello/</title>
    <link rel="canonical" href="https://example.com/some-page/hello/" />
    <meta name="robots" content="noindex">
    <meta charset="utf-8" />
    <meta http-equiv="refresh" content="0; url=https://example.com/some-page/hello/" />
  </head>

</html>
2 Likes

@pointyfar lays it out, so here’s a way to think about it: if I have a page that exists, and a bunch of URLs I want to redirect to it, I’d keep all those URLs in the one actual piece of content. Otherwise I’m just filling out empty pages to create redirects.

You’re simply thinking of it backwards. Set an alias as another path into your content, the main URL of which is set in the normal Hugo-esque way via the Title or, via slug in frontmatter for example. If you change the url multiple times, you can put all the old urls in the aliases list, so that you ensure visitors will still find your content, even if they have bookmarked the old url.

1 Like