As a blogger today, I wanted to redirect URLs that point to a subdirectory to an external destination.

In the blog post ‘Using Hugo as a redirect service’ by Daniel Terhorst-North I came across a very lean solution.

To achieve this, the following file must be created in the theme folder: /layouts/redirect/single.html.

The following source code must be added to the file:

{{- template "_internal/alias.html" (dict "Permalink" .Params.target) -}}

You can now create a file and define the redirect with the following four lines. The filename also determines the directory of the source URL:

---
type: redirect
target: https://google.de
---

The text was automatically translated from German into English. The German quotations were also translated in sense.