Robots.txt File
To generate a robots.txt file from a template, change the site configuration:
config.
enableRobotsTXT: true
enableRobotsTXT = true
{
"enableRobotsTXT": true
}
By default, Hugo generates robots.txt using an internal template.
User-agent: *
Search engines that honor the Robots Exclusion Protocol will interpret this as permission to crawl everything on the site.
Robots.txt Template Lookup Order
You may overwrite the internal template with a custom template. Hugo selects the template using this lookup order:
/layouts/robots.txt
/themes/<THEME>/layouts/robots.txt
Robots.txt Template Example
layouts/robots.txt
User-agent: *
{{ range .Pages }}
Disallow: {{ .RelPermalink }}
{{ end }}
This template creates a robots.txt file with a Disallow
directive for each page on the site. Search engines that honor the Robots Exclusion Protocol will not crawl any page on the site.