From 5741e681814ef29a084179297f980744c732a2a2 Mon Sep 17 00:00:00 2001 From: manue Date: Mon, 14 Sep 2026 19:37:09 +0200 Subject: [PATCH] fix(seo): redirect non-canonical domains to www.mnqcatering.com mnqeventos.es (and the bare mnqcatering.com apex) were serving the same content as www.mnqcatering.com with no redirect, causing duplicate content. Add middleware that 301-redirects any request whose host isn't exactly www.mnqcatering.com to the canonical domain, preserving path and query. Still needs verification at the reverse-proxy/hosting layer, since host detection here depends on how the Host header arrives in production. --- src/middleware.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/middleware.ts diff --git a/src/middleware.ts b/src/middleware.ts new file mode 100644 index 0000000..3489c0d --- /dev/null +++ b/src/middleware.ts @@ -0,0 +1,26 @@ +import { defineMiddleware } from 'astro:middleware'; + +const CANONICAL_HOST = 'www.mnqcatering.com'; + +/** + * SEO: this site is undesirably mirrored at mnqeventos.es (same content, no + * redirect at the DNS/hosting level). This middleware enforces the canonical + * host at the application layer for any host that isn't exactly + * www.mnqcatering.com (covers mnqeventos.es, www.mnqeventos.es, and the bare + * mnqcatering.com apex). + * + * NOTE: this must also be verified at the reverse-proxy/hosting layer — host + * detection here depends on how the Host header (or X-Forwarded-Host, when + * behind a proxy) actually arrives in production. If the proxy doesn't + * forward the original host, this check will see the wrong value. + */ +export const onRequest = defineMiddleware((context, next) => { + const requestHost = context.url.host; + + if (requestHost !== CANONICAL_HOST) { + const redirectUrl = new URL(context.url.pathname + context.url.search, `https://${CANONICAL_HOST}`); + return context.redirect(redirectUrl.toString(), 301); + } + + return next(); +});