Hugo redirect from alias to canonical URL?

Is it possible hugo to produce 301 redirect html pages from aliases in frontmatter
or from a central config file like middleman?

Not that I know of. But you can do it the other way round:

Rename your file or slug to whatever it should be and set an alias to the old file path.

301 redirects isn’t possible from a static site generator alone (I doubt that Middleman does this).

But you can produce Netlify “_redirects” file and similar to enable this. There are examples around.

1 Like

As your linked doc says, Middleman does not create 301 redirects but provides an alternative:

However, in some cases, you will not have access to the server to add this feature. Middleman can generate HTML files which will redirect your visitors, but, these old paths are likely to still appear in search engines and will negatively impact your SEO.

The equivalent of that in Hugo is the aliases front-matter parameter:

A _redirect example — Here’s a Netlify _redirect I use for one of my Hugo-generated sites.

You are right about 301 redirects My mistake.
That would require http header manipulation which cannot be done with serving static HTML.

But, is it possible to create automatically html pages with ,
based on aliases on frontmatter?

The current aliases use, as it creates a second page with another URL for the same content, I think, its bad for SEO.


Yes, it is not optimal for SEO, but search engines will correct your URLs after some time.

But if you use the way I suggested above just one HTML file with content and the correct file name is created:

All aliases HTML files just contain something like this:

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

So there is no duplicate content. And Hugo uses a canonical tag and noindex for search engines out of the box. Hugo is clever!

Moreover, you can use the canonical tag in your layouts:

<link rel="canonical" href="{{ .Permalink }}">

As you said: A static website generator itself cannot support ‘real’ redirects—also Middleman can’t. If you have a choice you should use e.g. .htaccess or Netlify redirects.


@Grob Your answer is great and complete and should be transferred to hugo docs! Thanks

1 Like