Netlification v1.2.6

This is a Hugo theme component with helpers to host your GoHugo generated static website on Netlify. If you don’t use Netlify, you DO NOT need this module.

Add this module
	path = ""
	disable = false
	ignoreConfig = false
	ignoreImports = false
Latest Version v1.2.6 (2022-08-25)
Fix to this version
hugo mod get[email protected]


Redirects: Adds redirects via HTTP headers. This redirection is faster and SEO wise better than Hugo’s method of adding meta-refresh commands in dedicated files.

CSP: Adds Content Security Policies for improved security.

Headers: Adds headers with caching and security directives to improves security and speed.

Installation and setup

Step 1: enable modules in your own repository

1hugo mod init

Step 2: add the module to your required modules in config.toml:

3  path = ''
2  imports:
3  - path:
2   "module": {
3      "imports": [
4         {
5            "path": ""
6         }
7      ]
8   }

or in your config/module.toml:

2path = ''
2- path:
2   "imports": [
3      {
4         "path": ""
5      }
6   ]

The next time you run hugo it will download the latest version of the module.

Step 3: Add REDIR and HEADERS to your home output formats:

2  home = ['REDIR', 'HEADERS']
2  home:
3  - REDIR
2   "outputs": {
3      "home": [
4         "REDIR",
5         "HEADERS"
6      ]
7   }

You should already have an [outputs] section, add "REDIR", "HEADERS" to it. Add them to the home parameter, not to other definitions.



Per post

Redirection takes aliases that are defined in the pages frontmatter and creates a 301 redirect for them. This is done via HTTP headers as opposed to the redirects via HTML meta tags that Hugo is doing. This is faster and might be better for SEO.

Keep defining them via frontmatter and let Netlification do the rest.

1aliases = ['url1', 'url2', 'url3']
2- url1
3- url2
4- url3
2   "aliases": [
3      "url1",
4      "url2",
5      "url3"
6   ]

Additional Redirects

  • A redirect for 404 errors to Hugo’s 404 page (/layouts/404.html) - no action by you required

  • A redirect for your default URL to your live URL via data configuration in data/dnb/netlification/config.toml

    2netlify = ''
    2- netlify:
    2   "redirects": [
    3      {
    4         "netlify": ""
    5      }
    6   ]

    The URL will be redirected to your baseURL. Right now this feature requires a trailing slash on both, baseURL and netlify parameter

  • Add more redirects as required. Each redirect requires a header [[redirects]] followed by at least the parameters from and to:

    2from = '/old-contact-form/'
    3status = 200
    4to = '/contact/'
    2- from: /old-contact-form/
    3  status: 200
    4  to: /contact/
    2   "redirects": [
    3      {
    4         "from": "/old-contact-form/",
    5         "status": 200,
    6         "to": "/contact/"
    7      }
    8   ]

    You can add a status property, if you wish to output any other code than 301 for the redirect. The status property is optional and is explicitly intended for redirect cases.

    The format of these redirect tables is identical to redirects format used in the Netlify configuration file format.

Disable internal alias creation in Hugo

If you are using Netlification you can speed up Hugo’s page creation process a little bit by setting the config variable disableAliases to true. This will disable the default behaviour of creating an HTML file per alias to redirect via meta tags and speed up site generation.


Netlification uses considerate caching options. Stylesheets, javascripts, images and other media files are cached for a full year. Netlification expects you to use Hugo pipes to create those files, which will result in unique URLs after you change the content of the files.

Content Security Policy

Have a look in data/dnb/netlification/config.toml or data/dnb/netlification/sample-config.toml to learn more.

You can check your content security policy using these following services and audits:

Sample Configuration

Add your configuration in data/dnb/netlification/config.toml. A sample configuration can be found in data/dnb/netlification/sample-config.toml


To update this module:

1hugo mod get -u

To update all modules:

1hugo mod get -u

Extend netlification headers from other modules

hugo-netlification offers an easy way to plug into the _headers file. Just add a file at /data/namespacename/modulename/netlification.toml and follow the instructions about header formats at These rules are added after the rules by hugo-netlification.


  • Netlify’s redirects engine will process the first matching rule it finds, reading from top to bottom. Rules in the _redirects file are always processed first, followed by rules in the Netlify configuration file.

Testing output