Manage Redirect with Bissetii in Hugo

Managing redirect in Hugo can be cumbersome so Bissetii came out with an easier solution to handle the task. Through using Bissetii, any page can be set to redirect with simple setup in the Page's front matter.

Setup Page Redirect

Bissetii allows you to setup redirect URL easily using the redirectURL field in the page’s Hugo front matter. You can specify both absolute and Bissetii compatible relative destination URL.

Example:

1
2
3
4
5
6
7
8
+++
...
draft = false
type = ""
redirectURL="/en/components/link/"
layout = "single"
+++
...

Activate Page Redirect

To activate or deactivate the redirect, you need to set the layout between redirect and other layouts. What Bissetii did was to use meta refresh redirect with 0 second mechanism layout to perform the page redirection and process the corresponding sitemap not to include the initiator page in its map.

To activate, simply set the layout to redirect as follows:

1
2
3
4
5
6
7
8
+++
...
draft = false
type = ""
redirectURL="/en/components/link/"
layout = "redirect"
+++
...

To deactivate, simply change the layout to something else (e.g. single or list depending on content) as follows:

1
2
3
4
5
6
7
8
+++
...
draft = false
type = ""
redirectURL="/en/components/link/"
layout = "single"
+++
...

Hiding The Menu Item

While the page can be redirected, the menu item does not. In fact, there is a very high chance you will create the same colliding menu item. Hence, remember to hide or disable the menu item from being usable. See Manage Menu for how to do it.

Here is an example for disabling the menu item via the page’s Hugo front matter:

1
2
3
4
5
6
7
8
9
+++
...
[menu.main]
parent = "disabled"
name = "My Title (Disabled)"
pre = "๐Ÿ““"
weight = 5
...
+++

Be Careful

While using Bissetii’s redirect implementation is a lot easier than the Hugo counterpart, there is no way to defend against infinity redirect looping.

Please make sure your redirected URL will not cause such consequences before enabling.

Wrapping Up

That is all for managing redirect with Bissetii in Hugo. If you have any question to ask us directly, please feel free to raise it at our GitLab Issues Section. We will be happy to assist you.