Skip to content

fix(seo): resolve 300+ compare page 404s via dynamic SSR + 3-card support #2

@phucbm

Description

@phucbm

Problem

300+ /so-sanh/X-vs-Y URLs reported as 404 in Google Search Console this week. Root causes:

  1. Static export on Cloudflare Pages only serves API-curated pairs — unknown pairs 404
  2. Existing SoSanh404Redirect is client-side JS only — Google sees HTTP 404, not a redirect
  3. Root-level /X-vs-Y URLs (missing /so-sanh/ prefix) had no redirect handler
  4. 3-card comparison URLs (/so-sanh/A-vs-B-vs-C) were broken due to indexOf('-vs-') only finding first match

Solution

Migrated from Cloudflare Pages static export to Vercel SSR.

Changes (merged in ef56792, 1429b33)

app/(marketing)/so-sanh/[pair]/page.tsx

  • dynamicParams = true — unknown pairs render via SSR instead of 404
  • revalidate = 3600 — ISR caching for dynamically rendered pairs
  • URL parsing changed from indexOf('-vs-') to split('-vs-') — supports 2 or 3 card slugs
  • Title renders all card names: cards.map(c => c.name).join(' vs ')

next.config.ts

  • Added server-side 301 redirect: /:pair([^/]*-vs-[^/]*)/so-sanh/:pair
  • Handles root-level compare URLs, fires only on single-segment paths (no redirect loop)

.env.example

  • Replaced real API key with placeholder your-api-key-here

Result

  • Curated pairs: pre-built static, fast, indexed ✓
  • Unknown 2-card pairs: SSR on first request, cached 1h, indexable by Google ✓
  • 3-card pairs (/so-sanh/A-vs-B-vs-C): SSR, full 3-column comparison ✓
  • Root-level /X-vs-Y: server-side 301 → /so-sanh/X-vs-Y
  • Invalid pairs (card not found): real 404 ✓

Follow-up

  • Submit affected URLs to Google Search Console for recrawl
  • Monitor Search Console for 404 count drop over next 2 weeks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions