moonming opened a new pull request, #2070: URL: https://github.com/apache/apisix-website/pull/2070
## Problem Versioned doc pages (`/docs/<project>/<version>/...`) self-canonicalize (Docusaurus default), so Google indexes every version as an independent page competing with the version-less latest URL. Search Console shows the resulting traffic migration over the last 28 days, e.g.: | URL | clicks (prev → current) | |---|---| | `/docs/apisix/plugins/cors/` (latest) | 69 → 14 | | `/docs/apisix/3.10/plugins/cors/` | 0 → 38 | | `/docs/apisix/plugins/prometheus/` (latest) | 125 → 36 | | `/docs/apisix/3.10/plugins/prometheus/` | 0 → 34 | The sitemap already excludes versioned URLs (#2063), but Google discovers them through the version switcher and, because each one claims to be its own canonical, ranks them instead of the latest URL. ## Fix Wrap the `LayoutHead` theme component in the doc workspace: when the pathname matches `/docs/<project>/<version|next>/...` (same version-segment pattern as `scripts/update-sitemap-loc.js`), emit a canonical + `og:url` pointing at the version-less URL. react-helmet's last-wins rule keeps the precedence intact: 1. default self-canonical (original `LayoutHead`) 2. this wrapper's latest-URL canonical (versioned/next pages only) 3. a canonical embedded in the doc markdown itself (e.g. the `docs.api7.ai` links some latest docs carry) still overrides everything ## Verification (production build) - `/docs/apisix/3.16/plugins/cors/` → canonical `https://apisix.apache.org/docs/apisix/plugins/cors/` - `/zh/docs/apisix/3.16/plugins/cors/` → canonical `https://apisix.apache.org/zh/docs/apisix/plugins/cors/` - `/docs/apisix/plugins/cors/` (latest) → canonical unchanged - `/docs/apisix/3.16/getting-started/README/` → markdown-embedded canonical unchanged - exactly one `rel=canonical` per page; `og:url` matches it ## Known limitation A page that exists only in an old version (deleted in latest) will get a canonical pointing at a 404 URL; Google ignores invalid canonicals, so the page falls back to self-canonical behavior. Acceptable vs. the complexity of existence-checking across versions at render time. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
