Custom robots.txt template not working

I get a ‘404 error not found’ response when using a custom robots.txt template. I:-

  1. Added enableRobotsTXT = true to the configuration file.
  2. Created a robots.txt file in the layouts folder with this content
User-agent: *
Sitemap: {{ site.Home.Sitemap.Filename }}

My best guess would be that you have not set enableRobotsTXT = true… In TOML that may happen if you put it after you have started a map, e.g. [params], but that’s guesswork.

I have done that Sir.

The params are in ./config/default/params.toml.

Perhaps I should ask, is the file visible in localhost with hugo serve command by default?

Yes…

I placed the code enableRobotsTXT = true before any code with the brackets [...] in the configuration file and I can see the result.

The layout files goes into “layouts/robots.txt” … NOT “layouts/_default/robots.txt”.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.