From 76f4c053ae621f180f9e5b8d014060b83789f8c8 Mon Sep 17 00:00:00 2001 From: Alejandro Veras Date: Wed, 21 Oct 2026 10:24:25 -0400 Subject: [PATCH] Answer 410 to spam URLs with paths in the query string --- src/proxy.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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) || "/";