跳至主要內容

    Meta Robots

    Meta robots 用來控制頁面是否被索引(index/noindex)以及連結是否被追蹤(follow/nofollow)。

    定義

    Meta robots 是放在 HTML <head> 的 <meta name="robots" content="..."> 指令。它影響「索引」與「連結追蹤」行為,例如 noindex 表示不要把此頁放進搜尋結果;follow 表示仍可追蹤此頁的連結。

    為什麼重要

    • 避免站內搜尋、測試頁等低價值頁面出現在 SERP
    • 防止薄內容稀釋品質訊號與索引資源
    • 配合 canonical、sitemap 控制索引範圍(index scope)
    • 保護未完成頁面 — 開發中/測試頁用 noindex 防止被收錄
    • 管理分頁策略 — 第 2 頁以後 noindex 避免重複內容問題
    • 控制連結權重傳遞 — nofollow 防止權重流向低信任頁面
    • 細粒度爬蟲控制 — 可針對特定爬蟲(googlebot、bingbot)設定不同規則

    怎麼做(實作重點)

    • 要排除 SERP:用 noindex(不要用 robots.txt 擋住,否則看不到 noindex)
    • 想保留連結權重:用 noindex,follow(依需求調整)
    • 不要把 noindex URL 放進 sitemap,並確保 HTTP 狀態正確(200/301/404)
    • 動態頁面(篩選、排序)統一設定 noindex 防止索引膨脹
    • 使用 X-Robots-Tag HTTP header 處理非 HTML 資源(PDF、圖片)
    • 測試環境全站加上 noindex 或 robots.txt Disallow
    • 用 Search Console 網址檢查工具驗證 meta robots 是否正確被讀取

    範例

    html
    <!-- 預設(可省略):允許索引與追蹤連結 -->
    <meta name="robots" content="index, follow" />
    
    <!-- 不索引但追蹤連結(常用於分頁、篩選頁)-->
    <meta name="robots" content="noindex, follow" />
    
    <!-- 索引但不追蹤連結(用於外部連結頁面)-->
    <meta name="robots" content="index, nofollow" />
    
    <!-- 完全封鎖 -->
    <meta name="robots" content="noindex, nofollow" />
    
    <!-- 額外指令:不快取、不顯示摘要 -->
    <meta name="robots" content="noarchive, nosnippet" />
    
    <!-- 針對特定爬蟲 -->
    <meta name="googlebot" content="noindex" />
    <meta name="bingbot" content="noindex" />
    typescript
    // Next.js App Router - layout.tsx 或 page.tsx
    import { Metadata } from 'next';
    
    // 根據頁面類型設定
    export function generateMetadata({ params, searchParams }): Metadata {
      const isFilterPage = Object.keys(searchParams).length > 0;
      const isPaginatedPage = searchParams.page && Number(searchParams.page) > 1;
      
      return {
        robots: {
          index: !isFilterPage && !isPaginatedPage,
          follow: true,
          nocache: false,
          googleBot: {
            index: !isFilterPage && !isPaginatedPage,
            follow: true,
            'max-video-preview': -1,
            'max-image-preview': 'large',
            'max-snippet': -1,
          },
        },
      };
    }
    
    // 測試環境全站 noindex
    // next.config.js
    const isProduction = process.env.NODE_ENV === 'production';
    module.exports = {
      async headers() {
        if (!isProduction) {
          return [{
            source: '/:path*',
            headers: [{ key: 'X-Robots-Tag', value: 'noindex, nofollow' }],
          }];
        }
        return [];
      },
    };

    相關連結

    常見問題

    關於這個詞彙的常見問答。

    回到詞彙表