Skip to Content

IndexNow

IndexNow  lets a site tell search engines which URLs changed, instead of waiting to be crawled. One POST to api.indexnow.org is shared with every participating engine: Bing, Yandex, Seznam, Naver and others.

Google does not take part in IndexNow. For Google, the sitemap stays the channel.

django-cfg reads the sitemap sources you already registered, with the same URL template and fields as the feed, so IndexNow never announces a URL your sitemap would not list. Each run compares them with what the engines last accepted for the host, and sends:

  • new URLs, which no earlier run sent;
  • changed URLs, whose lastmod moved;
  • removed URLs, which left a source; the engine recrawls them and sees the 404 or redirect.

How a run behaves

  • Only an accepted batch is recorded. A 429, a 403 or a timeout leaves the state as it was, so the next run sends the same URLs again. A missed or failed run loses nothing.
  • The first run for a host records and sends nothing. The engines already have those URLs from your sitemap, and pushing a whole catalogue at once is what earns a 429.
  • A degraded read is not sent as fact. If any source raises, or the read is empty, nothing is sent. The same holds when more than shrink_share (20%) of known URLs vanish in one run: a partial read must not reach Bing as a mass removal. If the withdrawal is real, run indexnow_submit --reseed.
  • At most max_urls_per_run per host per run (10,000). Whatever is left goes out on the next run.
  • One run at a time. Runs take a cache lock, so a slow run that overlaps the next schedule cannot send the same diff twice.
  • Everything is visible. Admin → Sitemap shows each host’s last_status, last_run_at and last_success_at, and logs every POST with its HTTP status.

Setup

Configure

from django_cfg import DjangoConfig, IndexNowConfig class MyConfig(DjangoConfig): indexnow = IndexNowConfig( key="865178f53dba1db23f3fc4fe95e9b64a", # public by protocol host="example.com", # optional: the public host, not the API's trailing_slash=True, # match your canonical URLs )

host is optional. Without host or sites, the host of the project’s single site (the host of its site_url) is used. With several sites declared, name them with sites or host, otherwise the config is rejected (“set sites or host”).

Generate a key with python -c "import secrets; print(secrets.token_hex(16))". It is not a secret: every engine fetches it from your site.

Serve the key file

The protocol proves you own the host by fetching https://<host>/<key>.txt. Django already answers it at /cfg/sitemap/indexnow/<key>.txt. Any other name returns 404, so the route cannot be used to probe for the key.

When the public host is a Next.js app, rewrite to Django. Use fallback, so real files like robots.txt always win:

// next.config.ts import { createBaseNextConfig, indexNowKeyRewrite } from '@djangocfg/nextjs/config'; export default createBaseNextConfig({ async rewrites() { return { beforeFiles: [], afterFiles: [], fallback: [indexNowKeyRewrite(process.env.NEXT_PUBLIC_API_URL!)], }; }, });

When Django serves the public host itself, point key_location at the Django route instead.

Check, then send

curl https://example.com/<key>.txt # must print the key python manage.py migrate # the state tables (django_sitemap) python manage.py indexnow_submit --dry-run # what would be sent; records nothing python manage.py indexnow_submit # first run: records, sends nothing

From then on an RQ job runs hourly. It is registered automatically from the config. Set schedule_interval=0 to turn it off. A run reads every source and can take minutes: queue="cache" (any queue declared in django_rq.queues) keeps it off the worker that serves latency-bound jobs.

The first submission from a new key returns 403 SiteVerificationNotCompleted, because the service has not fetched your key file yet. Retry after a few minutes. If /<key>.txt already answers 200, this is not a configuration error.

Several sites on one backend

When one Django serves several public sites, each on its own domain (one catalogue under several brands, say), declare a site per host. IndexNow takes one host per request, and every URL in it must be on that host, so each site is submitted separately.

from django_cfg import IndexNowConfig, IndexNowSite indexnow = IndexNowConfig( key="865178f53dba1db23f3fc4fe95e9b64a", trailing_slash=True, sites=[ IndexNowSite(host="caribbean.example.com", source_suffix="-caribbean"), IndexNowSite(host="bali.example.com", source_suffix="-bali"), ], )
  • A site takes its sources by source_suffix (properties-caribbean, stories-caribbean, …), by an explicit sources=[...] list, or both. A source no site takes is not sent anywhere.
  • One key serves every host by default. Give a site its own with IndexNowSite(key=...). The Django route answers every configured key, and each frontend rewrites /<key>.txt to it (indexNowKeyRewrite). Set key_location on a site that serves its key elsewhere.
  • trailing_slash on a site overrides the config’s.
  • extra_urls must return absolute URLs here: a bare path could belong to any site, so it is skipped with a warning. URLs are grouped by host, and a URL on a host that is not a configured site is refused before sending.
  • Name a site by host, or by site="key", a DjangoConfig.sites key whose site_url host becomes the host. Set exactly one of the two on each IndexNowSite.
  • host and sites on the config are mutually exclusive.
indexnow = IndexNowConfig( key="865178f53dba1db23f3fc4fe95e9b64a", sites=[ IndexNowSite(site="caribbean", source_suffix="-caribbean"), IndexNowSite(site="bali", source_suffix="-bali"), ], )

URLs the sitemap never listed

The diff covers every URL that enters or leaves a sitemap source. Some pages change their answer without ever having been in a sitemap: a listing your sitemap never offered that now returns 410, say. Return those from a function and name it in extra_urls:

# apps/catalog/indexnow.py from datetime import datetime, timedelta from apps.catalog.models import Listing def gone_urls(since: datetime) -> list[str]: """Listings removed since the last successful run: they now 410.""" return [ f"/listings/{pk}" for pk in Listing.objects.filter(removed_at__gte=since).values_list("pk", flat=True) ]
indexnow = IndexNowConfig(key=..., host="example.com", extra_urls="apps.catalog.indexnow.gone_urls")

since is the start of the host’s last fully successful run, so a failed run does not skip a span. These URLs are sent once and are not diffed. Paths are joined to host; absolute URLs are sent as they are.

Calling it from code

from django_cfg.modules.django_sitemap import indexnow indexnow.submit(["https://example.com/listings/42"]) # request paths: never raises indexnow.submit_changed() # the run: raises IndexNowError on a refusal

submit() returns sent, accepted and errors. A search engine being down must not fail a save, so it reports the failure instead of raising. It is logged, but it does not update the diff state, so the next run may send the same URL once more.

Commands

python manage.py indexnow_submit # one run, every site python manage.py indexnow_submit --dry-run # counts and a sample; records nothing python manage.py indexnow_submit --host example.com # one site python manage.py indexnow_submit --reseed # forget the state; the next run records and sends nothing python manage.py indexnow_submit --url https://example.com/a/ # push these now

Reference

FieldDefaultNotes
keyrequired8–128 characters of [A-Za-z0-9-].
hostthe project’s site hostBare hostname. Every URL must be on it, or the batch is refused with 422. Exclusive with sites.
sites—IndexNowSite(host or site, key, source_suffix, sources, key_location, trailing_slash) per public host.
key_locationhttps://<host>/<key>.txtWhere the engines fetch the key.
trailing_slashFalseAppend / to paths, for slash-canonical sites.
sourcesevery enabled sourceSingle-site: limit which sources are read. A source without lastmod_field is sent only when a URL appears or goes.
extra_urls—Dotted path to callable(since) -> list[str].
max_urls_per_run10000Per host per run; the rest goes on the next run.
shrink_share / shrink_floor0.2 / 50A run that loses more than this many known URLs sends nothing.
schedule_interval3600Seconds between RQ runs. 0 turns the schedule off.
queue"default"RQ queue of the scheduled run. Use a long-job queue such as "cache"; it must be declared in django_rq.queues.
endpointhttps://api.indexnow.org/indexnowShared by every engine.
timeout30Seconds per request.
StatusMeaning
200, 202Received.
403The key file is missing, wrong, or not yet verified (see above).
422A URL is not on host, or the key does not match the host.
429Too many requests. Nothing is recorded, so the next run retries.

Try it in the demo

The demo project wires all of this behind two environment variables:

INDEXNOW__KEY=$(python -c "import secrets; print(secrets.token_hex(16))") \ INDEXNOW__HOST=example.com \ python manage.py indexnow_submit --dry-run

See api/settings/config.py (indexnow = …) and next.config.ts (indexNowKeyRewrite) in the demo.

Last updated on