Redirect the root with a real 301 instead of a static stub

This commit is contained in:
Djeex
2026-09-05 23:01:15 +02:00
parent 7425a484c2
commit 95d6341fa7
+15 -6
View File
@@ -91,12 +91,14 @@ export default defineNuxtConfig({
// path to its slash form. Back to `path/index.html` so what's on disk // path to its slash form. Back to `path/index.html` so what's on disk
// matches the URLs we advertise. // matches the URLs we advertise.
autoSubfolderIndex: true, autoSubfolderIndex: true,
// Docus only seeds `/en` and `/fr` (one per locale), so neither `/` nor // Docus only seeds `/en` and `/fr` (one per locale), so `/robots.txt`
// `/robots.txt` is ever written and both 404 on a static host — `/` loses // is never written and 404s on its own, losing the `Sitemap:` line
// the redirect to the default locale, and robots.txt loses the `Sitemap:` // crawlers need to find sitemap.xml. It exists server-side, it just
// line pointing crawlers at sitemap.xml. Both routes exist server-side, // needs to be prerendered. `/` is deliberately NOT listed here: it
// they just need to be prerendered. // redirects to `/en/` (see routeRules below with `prerender: false`),
routes: ['/', '/robots.txt'], // and prerendering a redirect bakes it as a client-side meta-refresh
// stub with no SEO tags instead of a real 301.
routes: ['/robots.txt'],
}, },
}, },
// Keeps <NuxtLink> hrefs (including the ones i18n's switchLocalePath builds // Keeps <NuxtLink> hrefs (including the ones i18n's switchLocalePath builds
@@ -135,6 +137,13 @@ export default defineNuxtConfig({
// and friends, where the words are the same in both languages) are absent on // and friends, where the words are the same in both languages) are absent on
// purpose: a rule there would redirect the page to itself. // purpose: a rule there would redirect the page to itself.
routeRules: { routeRules: {
// Without this, `/` is a prerendered stub containing only a client-side
// `<meta http-equiv="refresh">` to `/en` (nuxt/i18n's static fallback
// for a locale redirect with no server request to inspect at prerender
// time). Crawlers and OG-preview tools don't execute that refresh, so
// they read the stub's empty head and find no title, description, or
// og:image. A real 301 fixes that: they land on `/en/` directly.
'/': { redirect: { to: '/en/', statusCode: 301 }, prerender: false },
// English, previously served at the site root. // English, previously served at the site root.
'/about/welcome': { redirect: { to: '/en/about/welcome/', statusCode: 301 } }, '/about/welcome': { redirect: { to: '/en/about/welcome/', statusCode: 301 } },
'/general/networking/nat': { redirect: { to: '/en/general/networking/nat/', statusCode: 301 } }, '/general/networking/nat': { redirect: { to: '/en/general/networking/nat/', statusCode: 301 } },