From 22604423c8ae1d572b847025f69707cbc7d983fe Mon Sep 17 00:00:00 2001 From: sktbrd Date: Wed, 8 Jul 2026 18:39:39 -0300 Subject: [PATCH] fix(seo): default sitemap + robots to canonical www host MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sitemap.xml and robots.ts defaulted NEXT_PUBLIC_SITE_URL to https://gnars.com while metadataBase (layout) and BASE_URL (config) default to https://www.gnars.com. With the env var unset in prod, the sitemap emitted 2,564 non-www URLs that all 307-redirect to www, and the page canonicals point to www — so Google dropped almost the whole site (down to ~8 indexed pages). Align both defaults (and env.example) to the canonical www host so sitemap/robots/canonical agree. Co-Authored-By: Claude Opus 4.8 (1M context) --- env.example | 2 +- src/app/robots.ts | 5 ++++- src/app/sitemap.xml/route.ts | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/env.example b/env.example index 4eaaa1b7..abe7fc90 100644 --- a/env.example +++ b/env.example @@ -3,7 +3,7 @@ # =========================================== # Site Configuration -NEXT_PUBLIC_SITE_URL=https://gnars.com +NEXT_PUBLIC_SITE_URL=https://www.gnars.com NEXT_PUBLIC_BASE_URL=http://localhost:3000 # =========================================== diff --git a/src/app/robots.ts b/src/app/robots.ts index 74a109db..2cec8479 100644 --- a/src/app/robots.ts +++ b/src/app/robots.ts @@ -1,6 +1,9 @@ import type { MetadataRoute } from "next"; -const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || "https://gnars.com"; +// Canonical host is www.gnars.com (matches metadataBase in [locale]/layout.tsx +// and BASE_URL in lib/config.ts). Keeping this in sync is what lets Google index +// the site — a non-www default here made every sitemap URL a redirect to www. +const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || "https://www.gnars.com"; export default function robots(): MetadataRoute.Robots { const normalized = SITE_URL.replace(/\/+$/, ""); diff --git a/src/app/sitemap.xml/route.ts b/src/app/sitemap.xml/route.ts index 55477359..f74bc1f9 100644 --- a/src/app/sitemap.xml/route.ts +++ b/src/app/sitemap.xml/route.ts @@ -30,7 +30,10 @@ const PROPOSAL_PAGE_SIZE = 200; const MAX_COIN_PAGES = 50; const COIN_PAGE_SIZE = 200; -const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || "https://gnars.com"; +// Canonical host is www.gnars.com (matches metadataBase in [locale]/layout.tsx +// and BASE_URL in lib/config.ts). A non-www default here emitted 2,564 URLs that +// all 307-redirected to www, so Google dropped them — keep this on www. +const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || "https://www.gnars.com"; const BASE = SITE_URL.replace(/\/+$/, ""); const toUrl = (path: string) => new URL(path, `${BASE}/`).toString();