Redirects on Hugo

Create redirects on Hugo with our guide. Follow our step-by-step instructions to ensure a seamless user experience and improve your website's SEO.

The Hugo Redirect Plugin is a Hugo plugin that allows you to create redirect rules for your website. It generates redirect rules by reading a CSV file that contains old URLs and their corresponding new URLs.

Install Hugo-Redirect

Add hugo-redirect as a submodule

1
git submodule add https://github.com/gcc42/hugo-redirect.git themes/hugo-redirect

Add to .yaml or .toml

.yaml:

1
theme: ["hugo-redirect", "my-theme"]

.toml:

1
theme = ["hugo-redirect", "my-theme"]

Make a Redirect

go to your root directory for Hugo and run:

1
hugo new redirect/[REDIRECT-NAME.md]

The format of the redirect should be:

1
2
3
4
type = "redirect"
url = "/[URL-RELATIVE-TO-YOUR-SITE]"
redirect_to = "/[URL-LOCATION]"
redirect_enabled = true

Example

Redirect file for mansoorbarri.com/github is:

1
2
3
4
5
6
+++
type = "redirect"
url = "/github"
redirect_to = "https://github.com/mansoorbarri"
redirect_enabled = true
+++

You can add as many redirects as you like using this method.

that’s it <3