|Add this module|
[[module.imports]] path = "github.com/davidsneighbour/hugo-netlification" disable = false ignoreConfig = false ignoreImports = false
|Fix to this version||
hugo mod get github.com/davidsneighbour/[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 github.com/username/reponame
Step 2: add the module to your required modules in
or in your
The next time you run hugo it will download the latest version of the module.
Step 3: Add
HEADERS to your home output formats:
You should already have an
[outputs] section, add
"REDIR", "HEADERS" to it. Add them to the
home parameter, not to other definitions.
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.
A redirect for 404 errors to Hugo’s 404 page (
/layouts/404.html) - no action by you required
A redirect for your default netlify.com URL to your live URL via data configuration in
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
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
true. This will disable the default behaviour of creating an HTML file per alias to redirect via meta tags and speed up site generation.
Content Security Policy
You can check your content security policy using these following services and audits:
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 github.com/davidsneighbour/hugo-netlification
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 docs.netlify.com. These rules are added after the rules by
- Netlify’s redirects engine will process the first matching rule it finds, reading from top to bottom. Rules in the
_redirectsfile are always processed first, followed by rules in the Netlify configuration file.