用 IndexNow 快速提交网址给 Bing(附批量脚本)
发布新文章后等搜索引擎自己抓取,动辄几天。IndexNow 提供了一条更直接的路:你主动告诉搜索引擎「这个 URL 更新了」,对方立刻安排抓取。
它由微软发起,目前 Bing、Yandex、Seznam、Naver 等支持,Google 目前不参与。
原理
三个角色:
- 你在网站根目录放一个密钥文件,文件名和内容都是这个 key
- 向
api.indexnow.org发一个请求,带上 key 和 URL 列表 - 搜索引擎会验证根目录的密钥文件,然后抓取这些 URL
密钥文件示例:public/8f4d2a91c6b348e7a5d0f1c9b7e24d63.txt,内容就是:
8f4d2a91c6b348e7a5d0f1c9b7e24d63
访问 https://example.com/8f4d2a91c6b348e7a5d0f1c9b7e24d63.txt 能拿到这个字符串就算配置成功。
单条提交
curl "https://api.indexnow.org/indexnow?url=https://example.com/blog/hello/&key=你的key"
批量提交
更常用的是批量接口,一次最多 10000 条:
curl -X POST "https://api.indexnow.org/indexnow" \
-H "Content-Type: application/json; charset=utf-8" \
-d '{
"host": "example.com",
"key": "你的key",
"keyLocation": "https://example.com/你的key.txt",
"urlList": [
"https://example.com/blog/a/",
"https://example.com/blog/b/"
]
}'
返回 200 表示全部接受,202 表示已接受待处理,400 通常是 key 校验失败,403 是密钥文件访问不到。
用 Node 读 sitemap 自动推送
避免每次手动整理 URL,直接从构建产物里读:
const fs = require("fs");
const SITE = "https://example.com";
const KEY = "你的key";
const xml = fs.readFileSync("out/sitemap.xml", "utf-8");
const urls = [...xml.matchAll(/<loc>(.*?)<\/loc>/g)]
.map((m) => m[1].trim())
.filter((u) => u.startsWith(SITE));
const res = await fetch("https://api.indexnow.org/indexnow", {
method: "POST",
headers: { "Content-Type": "application/json; charset=utf-8" },
body: JSON.stringify({
host: new URL(SITE).host,
key: KEY,
keyLocation: `${SITE}/${KEY}.txt`,
urlList: urls,
}),
});
console.log(res.status);
配合 package.json:
{
"scripts": {
"push:seo": "node push-seo.js"
}
}
发布流程变成:npm run build → 上传 out/ → npm run push:seo。
顺序不能反:先推送再部署,搜索引擎抓到的就是 404,反而伤害站点。
去重很重要
IndexNow 建议同一个 URL 不要频繁重复提交。稳妥做法是本地记录推送时间,24 小时内跳过:
const state = JSON.parse(fs.readFileSync(".seo-push-state.json", "utf-8") || "{}");
const pending = urls.filter((u) => {
const last = state[u];
return !last || Date.now() - new Date(last).getTime() > 24 * 3600 * 1000;
});
推送成功后再把时间写回文件,并把这个状态文件加进 .gitignore。
和其他提交方式的区别
| 方式 | 覆盖引擎 | 时效 | 配额 |
|---|---|---|---|
| IndexNow | Bing / Yandex 等 | 分钟级 | 基本无限制 |
| 百度主动推送 | 百度 | 小时级 | 每天很少 |
| sitemap | 全部 | 天到周 | 无 |
| 手动提交 URL | 各家 | 天 | 少 |
所以合理组合是:sitemap 打底 + IndexNow 面向 Bing/Yandex + 百度 API 面向国内。Google 只能靠 sitemap 和 Search Console 手动提交。
常见问题
Google 支持 IndexNow 吗?
目前不支持。Google 侧仍然依赖 sitemap 和 Search Console 的 URL 检查。
key 可以随便写吗?
建议用随机字符串(至少 8 位,只含字母数字和短横线),并且每个站点用不同的 key。
密钥文件放在 public 下会被收录吗?
不影响。可以在 robots.txt 里 Disallow 掉 /*.txt,但保证搜索引擎校验时能访问到。本站的构建配置里就把 .txt 排除出了 sitemap。
推送后多久能看到收录?
Bing 通常几小时内,Yandex 更快。具体仍取决于内容质量和站点权重。
推送了但报 403 怎么办?
说明 keyLocation 无法访问。检查域名是否带 www、是否被 CDN 拦截、文件是否真的上传成功。