Skip to content

IndexNow for Astro

Easy

Anything in Astro's public/ directory is copied to the site root at build time.

Astro copies public/ verbatim into the build output, so a file there is served from your site root on every deploy without any configuration.

Step by step

  1. 1 Create public/a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6.txt in your Astro project.
  2. 2 Put the key in it as the only content.
  3. 3 Commit and deploy.
  4. 4 Confirm https://yourdomain.com/a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6.txt loads, then click Verify.

Or generate it at build time (src/pages/[key].txt.ts)

import type { APIRoute } from 'astro'

const KEY = import.meta.env.INDEXNOW_KEY ?? 'a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6'

export const GET: APIRoute = () =>
  new Response(KEY, {
    headers: { 'Content-Type': 'text/plain; charset=utf-8' },
  })

export function getStaticPaths() {
  return [{ params: { key: KEY } }]
}

The key shown is an example. Yours is generated when you add the domain.

Watch out for

  • The static file in public/ is simpler and works in both static and SSR output modes.

Then what?

Hosting the key file proves you own the domain — it doesn't submit anything on its own. You still need something watching for changes and calling the IndexNow API with the right URLs at the right time. You can build that yourself, or let us run it for $12 a year.

Set up automatic submission

Stop waiting to be found

Set it up once. We keep telling the search engines about every change you make, for $12 a year.