# Custom robots.txt template not working

**URL:** <https://discourse.gohugo.io/t/custom-robots-txt-template-not-working/37784>\
**Category:** support\
**Tags:** taxonomy\
**Created:** [March 21, 2022, 12:16pm UTC](https://discourse.gohugo.io/t/custom-robots-txt-template-not-working/37784 "2022-03-21T12:16:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![blade](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/blade/32/16585_2.png) [@blade](https://discourse.gohugo.io/u/blade)\
**Post date:** [March 21, 2022, 12:16pm UTC](https://discourse.gohugo.io/t/custom-robots-txt-template-not-working/37784/1 "2022-03-21T12:16:50Z")

</div>

> **[Robots.txt File](https://gohugo.io/templates/robots/)**
>
> Hugo can generate a customized robots.txt in the same way as any other template.

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

```auto
User-agent: *
Sitemap: {{ site.Home.Sitemap.Filename }}

```

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [March 21, 2022, 1:08pm UTC](https://discourse.gohugo.io/t/custom-robots-txt-template-not-working/37784/2 "2022-03-21T13:08:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![blade](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/blade/32/16585_2.png) [@blade](https://discourse.gohugo.io/u/blade)\
**Post date:** [March 21, 2022, 1:12pm UTC](https://discourse.gohugo.io/t/custom-robots-txt-template-not-working/37784/3 "2022-03-21T13:12:04Z")

</div>

> [@bep](#):
>
> My best guess would be that you have not set `enableRobotsTXT = true` …

I have done that Sir.

> [@bep](#):
>
> In TOML that may happen if you put it after you have started a map, e.g. `[params]`

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

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

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [March 21, 2022, 1:17pm UTC](https://discourse.gohugo.io/t/custom-robots-txt-template-not-working/37784/4 "2022-03-21T13:17:44Z")

</div>

> [@blade](#):
>
> Perhaps I should ask, is the file viewable in localhost with `hugo serve` command by default?

Yes…

---

<div class="post-metadata">

**Author:** ![blade](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/blade/32/16585_2.png) [@blade](https://discourse.gohugo.io/u/blade)\
**Post date:** [March 21, 2022, 1:32pm UTC](https://discourse.gohugo.io/t/custom-robots-txt-template-not-working/37784/5 "2022-03-21T13:32:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [March 21, 2022, 2:05pm UTC](https://discourse.gohugo.io/t/custom-robots-txt-template-not-working/37784/6 "2022-03-21T14:05:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [March 23, 2022, 2:06pm UTC](https://discourse.gohugo.io/t/custom-robots-txt-template-not-working/37784/7 "2022-03-23T14:06:12Z")

</div>

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