diff --git a/src/proxy.ts b/src/proxy.ts index c4d9b93..da3c291 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -4,9 +4,18 @@ import { defaultLocale, isLocale } from "@/i18n/config"; // Every page lives under app/[lang]. English keeps its unprefixed URLs, so those requests are // rewritten to /en internally, and /en/... is redirected back to the unprefixed address. export function proxy(request: NextRequest) { - const { pathname } = request.nextUrl; + const { pathname, searchParams } = request.nextUrl; const first = pathname.split("/")[1]; + // Spam sites link here with made-up paths in the query string (/?shop/items/L738.../). + // Answer 410 so search engines drop them instead of indexing copies of the page. + if ([...searchParams.keys()].some((key) => key.includes("/"))) { + return new NextResponse("Gone", { + status: 410, + headers: { "content-type": "text/plain; charset=utf-8", "x-robots-tag": "noindex" }, + }); + } + if (first === defaultLocale) { const url = request.nextUrl.clone(); url.pathname = pathname.slice(defaultLocale.length + 1) || "/";