0Pricing
HTML Academy · 课时

规范 URL 与 robots 元标签

使用元标签控制抓取并避免重复内容

规范 URL 与 robots 元标签 是 CoddyKit 上的免费 HTML Academy 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 HTML Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 HTML Academy 课程共包含 4 节课。

重复内容问题

搜索引擎可能会通过多个网址访问您的页面:

  • http://example.com/page
  • https://example.com/page
  • https://www.example.com/page
  • https://example.com/page/(末尾斜杠)
  • https://example.com/page?utm_source=newsletter

Google 必须决定要将哪个网址编入索引,并且可能会因重复内容而降低页面排名。

规范链接标签

使用 rel="canonical" 告诉搜索引擎首选网址:

<head>
  <!-- This is the canonical URL for this content: -->
  <link rel="canonical" href="https://example.com/blog/html5-guide">
</head>
<!-- No matter which URL the page is accessed from,
     this tag signals to Google which URL to index -->
<!-- Link equity is consolidated at the canonical URL -->

规范网址规则

规范网址最佳实践:

  • 使用完整的绝对网址(包括协议)
  • 如果网站支持 HTTPS,请使用 HTTPS
  • 保持一致:始终使用或始终不使用末尾斜杠
  • 每个页面都应有规范标签,即使它指向页面自身的网址
<link rel="canonical" href="https://example.com/blog/html5-guide">
<!-- NOT: -->
<!-- <link rel="canonical" href="/blog/html5-guide"> relative = bad -->
<!-- <link rel="canonical" href="http://..."> HTTP on HTTPS site = bad -->

分页与规范网址

对于分页内容,规范网址可以指向第一页或当前页面:

<!-- Page 2 of a blog listing: -->
<link rel="canonical" href="https://example.com/blog?page=2">
<!-- Or: consolidate all pages to the first -->
<link rel="canonical" href="https://example.com/blog">
<!-- Also useful: rel="prev" and rel="next" for paginated series -->

robots 元数据值

控制搜索引擎在每个页面上的行为:

<meta name="robots" content="index, follow">
<!-- Default: include in index and follow links -->

<meta name="robots" content="noindex">
<!-- Don't index this page -->

<meta name="robots" content="nofollow">
<!-- Don't follow links on this page -->

<meta name="robots" content="noindex, nofollow">
<!-- Don't index AND don't follow -->

<meta name="robots" content="noarchive">
<!-- Don't show cached version in search results -->

Googlebot 专用指令

使用专用指令针对特定抓取器:

<meta name="googlebot" content="noindex">
<!-- Only affects Google's crawler -->

<meta name="bingbot" content="noindex">
<!-- Only affects Bing's crawler -->

<!-- Other values: -->
<meta name="robots" content="max-snippet:50">
<!-- Limit snippet length in search results to 50 characters -->

<meta name="robots" content="max-image-preview:large">
<!-- Allow full-size image previews in Google results -->

X-Robots-Tag HTTP 标头

规范网址和 robots 也可以通过 HTTP 标头在服务器层面设置:

# Apache .htaccess:
Header add Link "<https://example.com/page>; rel=canonical"
Header add X-Robots-Tag "noindex"

# This is more powerful because it applies to non-HTML files too
# (PDFs, images, etc.) which can't have meta tags

robots.txt 与 robots 元数据对比

控制抓取器的两种工具——用途不同:

  • robots.txt — 控制抓取器可以访问哪些页面(访问控制)
  • robots 元数据 — 控制抓取器访问页面后如何处理页面(索引控制)

如果某个页面在 robots.txt 中被禁止访问,但其他地方存在指向它的链接,该页面仍可能被编入索引。带有 noindex 的页面则一定不会被编入索引。

站点地图与规范网址

您的站点地图只能列出规范网址:

<!-- sitemap.xml should list canonical URLs only: -->
<!-- https://example.com/blog/html5-guide (canonical) -->
<!-- NOT: https://www.example.com/blog/html5-guide -->
<!-- NOT: https://example.com/blog/html5-guide/ (trailing slash variant) -->

自引用规范网址

每个页面都应设置指向自身的规范网址,包括主页:

<!-- On https://example.com/about (the canonical URL itself): -->
<link rel="canonical" href="https://example.com/about">
<!-- This confirms: this IS the canonical URL -->
<!-- Prevents issues if the page is embedded in an iframe or scraped -->

电子商务中的规范网址

针对具有多个变体的商品,电子商务网站常用的规范网址模式:

<!-- Product page with color filter: -->
<!-- URL: /products/widget?color=blue -->
<link rel="canonical" href="https://example.com/products/widget">
<!-- All color variants point to the main product page -->
<!-- Avoids duplicate content penalty for parameter variants -->

快速检查

规范链接标签的 href 值应是什么?

回顾:规范网址与 robots

规范网址与 robots 要点:

  • <link rel="canonical" href="full-url"> — 声明首选网址
  • 规范网址使用绝对网址;始终使用 HTTPS
  • meta robots noindex — 从搜索索引中排除
  • meta robots nofollow — 不跟踪链接
  • robots.txt = 访问控制;robots 元数据 = 索引控制

常见问题解答

「规范 URL 与 robots 元标签」课时是免费的吗?

是的 — 「规范 URL 与 robots 元标签」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 HTML Academy 课程的其余内容,请升级到 CoddyKit PRO。 HTML Academy 课程共包含 4 节课。

「规范 URL 与 robots 元标签」这节课中我会学到什么?

使用元标签控制抓取并避免重复内容 你通过在浏览器中直接运行的动手代码来练习 HTML Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 HTML Academy 需要有经验吗?

无需任何先前经验。CoddyKit 上的 HTML Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。

「规范 URL 与 robots 元标签」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 HTML Academy 课中编写并运行代码吗?

能。每节 HTML Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. title 及其在 SEO 中的作用
  2. meta charset、viewport、author 和 description
  3. 规范 URL 与 robots 元标签
  4. 网站图标和 Apple Touch 图标
← 返回 HTML Academy