Skip to content

Cloudflare Pages 假 404 排查|Soft 404

這份排查用在 Cloudflare Pages 或 Astro / SPA 網站中,未知 URL 回傳 200 與首頁 HTML,導致 Google 判斷 soft-404 或 duplicate URL 風險。

症狀

  • https://www.example.com/this-page-does-not-exist 回 HTTP 200
  • 頁面內容看起來是首頁,而不是 404。
  • GSC 出現 Soft 404、Duplicate without user-selected canonical 或 Crawled currently not indexed。

為什麼有風險

未知 URL 回 200 會讓搜尋引擎以為每個不存在路徑都是有效頁面。如果內容又都是首頁,就可能造成:

  • 大量 duplicate URL。
  • soft-404 判定。
  • crawl budget 浪費。
  • 真正重要頁面的 indexing 訊號被稀釋。

修法

Astro / Cloudflare Pages 要有真 404

Astro 專案應建立 404 route,並讓不存在的靜態頁回真正的 404 status。Cloudflare Pages 不應把所有未知路徑 fallback 到首頁,除非它是明確需要 client-side router 的 SPA,且仍要處理 404 呈現與 status。

檢查項:

  • 是否有 src/pages/404.astro 或 framework 對應 404 檔案。
  • 是否有 Cloudflare Pages _redirects/* rewrite 到 /index.html 200
  • 是否有 adapter 或 middleware 改寫所有 unknown routes。

何時用 301

使用 301 的情境:

  • 舊 URL 有明確替代頁。
  • slug 改名但內容主題一致。
  • root / www / HTTP / HTTPS canonical 收斂。

何時用 404 / 410

使用 404:

  • URL 不存在。
  • 沒有明確替代頁。
  • 使用者或 bot 打到亂碼路徑。

使用 410:

  • 內容已永久移除。
  • 確定未來不會恢復,且希望搜尋引擎更快知道它不該保留。

驗證指令

Soft 404 驗證

確認未知 URL 回 404

Expected: HTTP status 應為 404

Terminal window
curl -I https://www.example.com/this-page-should-not-exist-404-check

HTML 內容抽查

確認內容不是首頁

Expected: 頁面應顯示 404 內容,不是首頁 hero

Terminal window
curl -s https://www.example.com/this-page-should-not-exist-404-check | head -40

常見錯誤

  • Cloudflare Pages _redirects 使用 /* /index.html 200,導致所有 unknown URL 都是首頁。
  • 以為畫面顯示 404 就好,但 HTTP status 仍是 200。
  • 把所有不存在頁面 301 到首頁,造成 soft-404。

完成標準

Checklist

Soft 404 修復檢查

P0

  • unknown URL 回 HTTP 404。
  • unknown URL 的 HTML 是 404 頁,不是首頁。
  • 只有有明確替代頁的舊 URL 才使用 301。
  • GSC URL Inspection 可看到修正後狀態。