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

package = "@netlify/plugin-sitemap"

  buildDir = "public/"
  trailingSlash = true
  exclude = [

(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:


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

  buildDir = "public"
  exclude = [

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:

package = "@netlify/plugin-sitemap"

  exclude = [

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.