站点收录:让搜索引擎知道你存在

站点上线了不代表会被搜到。主动提交一次,能显著缩短从「没人知道」到「能被搜到」的时间。

一、先确认基础三件套

bash
# 1. sitemap.xml 可访问
curl -I https://www.bzii.cn/sitemap.xml
# 200 + Content-Type: application/xml

# 2. robots.txt 可访问
curl -s https://www.bzii.cn/robots.txt

# 3. canonical 标签正确
curl -s https://www.bzii.cn | grep canonical

sitemap 示例:

xml
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://www.bzii.cn/#/post/domain-and-dns</loc>
    <lastmod>2026-09-02</lastmod>
    <changefreq>monthly</changefreq>
    <priority>0.7</priority>
  </url>
</urlset>

本站用 hash 路由,URL 里带 #搜索引擎对 hash 后的内容抓取能力弱,这是 hash 路由的固有代价(前面权衡过)。如果很在意收录,应该用 History API 路由。

二、各平台提交

平台地址验证方式
Googlesearch.google.com/search-consoleDNS TXT / HTML 文件 / meta 标签
Bingbing.com/webmasters同,可导入 Google 数据
百度ziyuan.baidu.comHTML 文件 / meta / CNAME
搜狗zhanzhang.sogou.comHTML 文件
360zhanzhang.so.comHTML 文件

验证方式选 DNS TXT 记录 最省事(不用上传文件):

bash
TXT  google-site-verification=一串字符
TXT  baidu-site-verification=一串字符

验证通过后提交 sitemap 地址。

三、主动推送(比等爬虫快得多)

百度:API 推送

bash
# 在站长平台拿到 token
curl -H "Content-Type:text/plain" \
  --data-binary @urls.txt \
  "http://data.zz.baidu.com/urls?site=www.bzii.cn&token=你的token"
bash
# urls.txt 每行一个 URL
https://www.bzii.cn/#/post/domain-and-dns
https://www.bzii.cn/#/post/server-bootstrap

成功返回:

json
{"remain":49990,"success":2}

Google:Indexing API(有限制)或等自动发现

Google 主要靠 sitemap + 外链发现。可以用 Search Console 的「网址检查」手动请求编入索引:

bash
1. 打开 Search Console
2. 顶部搜索框粘贴 URL
3. 点「请求编入索引」

Bing:提交 URL

bash
# Bing 有 IndexNow 协议,一次提交多家生效
curl -X POST https://api.indexnow.org/indexnow \
  -H "Content-Type: application/json" \
  -d '{"host":"www.bzii.cn","key":"<key文件>","urlList":["https://www.bzii.cn/#/post/x"]}'

四、自动化:新文章自动推送

本站的 tools/build-feeds.js 已经能生成 sitemap。加一段推送:

js
// tools/push-urls.js
const fs = require("fs");
const https = require("https");

const site = "www.bzii.cn";
const token = process.env.BAIDU_TOKEN;
const urls = fs.readFileSync("sitemap.xml", "utf8")
  .match(/<loc>([^<]+)<\/loc>/g)
  .map(s => s.replace(/<\/?loc>/g, "")).join("\n");

const req = https.request(`http://data.zz.baidu.com/urls?site=${site}&token=${token}`, {
  method: "POST",
  headers: { "Content-Type": "text/plain" }
}, res => {
  let d = "";
  res.on("data", c => d += c);
  res.on("end", () => console.log(d));
});
req.end(urls);

五、robots.txt 怎么写

bash
User-agent: *
Allow: /
Disallow: /admin/

Sitemap: https://www.bzii.cn/sitemap.xml

常见规则:

场景写法
完全禁止Disallow: /
禁止某目录Disallow: /private/
禁止某文件类型Disallow: /*.pdf$
禁止带参数的 URLDisallow: /*?
允许但禁止索引Disallow + 页面加 noindex

禁止抓取要用 Disallow,禁止索引要用 noindex 头。Disallow 的页面,爬虫看不到 noindex,反而可能被收录(只是没内容)。两个概念别混。

六、收录慢,怎么查

bash
# 1. 站点被收录了吗
# Google: site:www.bzii.cn
# 百度: site:www.bzii.cn

# 2. 爬虫能不能访问(很关键)
curl -A "Mozilla/5.0 (compatible; Baiduspider/2.0)" -I https://www.bzii.cn
curl -A "Googlebot" -I https://www.bzii.cn

# 返回 403/5xx 就是被拦了,检查 WAF 规则

# 3. robots.txt 有没有误伤
curl -s https://www.bzii.cn/robots.txt

# 4. 服务器日志里有没有爬虫来访
grep -i "spider\|bot" /var/log/nginx/access.log | tail -20

常见原因:

原因检查
Cloudflare 拦了爬虫看防火墙事件,加白名单
robots.txt 写错直接 curl 看
全是 JS 渲染抓取工具看不到正文
新域名没权重正常,需要时间
服务器返回 5xx看日志
bash
# 用站长平台的「抓取诊断」看爬虫眼中的页面
# 或者用 curl 模拟(不带 JS)
curl -s https://www.bzii.cn | head -50
# 如果正文为空 → 客户端渲染的问题

七、客户端渲染站点的补救

本站这类 JS 渲染的站点,收录天然吃亏。三种补救:

  1. 预渲染:构建时生成一份静态 HTML 副本,专门给爬虫(判断 UA);
  2. RSS + 主动推送:至少让内容进入索引库;
  3. 提供 sitemap + 站点本身的入口页有足够文字
nginx
# 简单版:给爬虫返回预渲染版本
if ($http_user_agent ~* "baiduspider|googlebot") {
    rewrite ^ /prerender/$uri last;
}

八、检查清单

  • sitemap.xml 可访问且内容正确
  • robots.txt 存在且没误伤
  • 各站长平台验证通过
  • sitemap 已提交
  • 关键页面手动请求过编入索引
  • 爬虫 UA 能正常访问(不被 WAF 拦)
  • canonical 标签正确
  • 有 RSS(feed.xml)

收录的核心不是技术,而是内容和外链。提交只是让「被发现」这个过程快一点,不能替代内容本身。