Exclude 404 page from sitemap

So for this gatsby website apexxglobal.netlify.app I am using Netlify’s sitemap plugin to generate its sitemap.

Now I wanted to exclude the 404 page from the sitemap and I have tried to achieve that by adding the paths to exclude. My netlfiy.toml file looks something like this

[[plugins]]
package = "@netlify/plugin-sitemap"

  [plugins.inputs]
  buildDir = "public/"
  trailingSlash = true
  exclude = [
    "./public/sitemap.xml",
    "./public/404/index.html",
    "./public/404/*",
    "./public/404.html",
    "*/404/*",
    "/404",
    "/404/",
    "**/404/"
  ]

(Last few lines were desperate attempts)
I have all tried to use “public” as buildDir but it didn’t help either.
What am I missing here?

Hi, @p-racoon. You can download the deploy to see the name of the file. There is a button in each successful deploy which is shown in the screenshot below:

download-deploy-button-small

Based on the filenames there, I believe the path that will work is this:

  • “./404/index.html”

If that doesn’t work or if there are other questions, please let us know.

Hey @luke, Thanks a lot for this
I tried with

[plugins.inputs]
  buildDir = "public"
  exclude = [
'./public/404/',
'./public/404/index.html',
'./public/404/*',
'404/*',
'404/index.html',
'./404',
'./404/',
'./404/index.html'
  ]

Didn’t seem to have worked :frowning:
Also, I am checking in the preview link rather than the main deployed link, hope that shouldn’t be an issue.

Hey @luke , the solution didn’t work is there something else that I can try?

I am surprised by all those filenames. Is your 404 file not called “404.html”? That is our docs’ recommendation, and then you should probably use /404.html in your exclude array, right?

the files are actually being generated by gatsby, and how its doing it is, it’s placing an index.html inside a folder named 404.
the filenames I used in exclude were my desperate attempts :sweat_smile: to prevent it from being added to the sitemap

Thanks for following up here with these details, @p-racoon :netlisparkles: Does this mean you are still encountering issues?

Yes, even though the project I was working on is done, this is one mystery I couldn’t solve for.

Let me escalate this for you… hang tight :grinning:

1 Like

Hi, @p-racoon. I believe this will work:

[[plugins]]
package = "@netlify/plugin-sitemap"

  [plugins.inputs]
  exclude = [
    '/404.html',
    '/404/index.html'
  ]

You can leave off the buildDir setting because that will default to your publish directory.

If that doesn’t fix it, please let us know.

1 Like

Hey sorry I have lost access to the project I was working on for this, and I am down with covid :mask: give me some time to emulate it for a different gatsby project. Will get back to you on this!

1 Like

Hi, @p-racoon. I wish you the best and hope you have a speedy recovery!

We will be here so there is no rush and please reply whenever time allows.