Answer 410 to spam URLs with paths in the query string
This commit is contained in:
+10
-1
@@ -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
|
// 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.
|
// rewritten to /en internally, and /en/... is redirected back to the unprefixed address.
|
||||||
export function proxy(request: NextRequest) {
|
export function proxy(request: NextRequest) {
|
||||||
const { pathname } = request.nextUrl;
|
const { pathname, searchParams } = request.nextUrl;
|
||||||
const first = pathname.split("/")[1];
|
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) {
|
if (first === defaultLocale) {
|
||||||
const url = request.nextUrl.clone();
|
const url = request.nextUrl.clone();
|
||||||
url.pathname = pathname.slice(defaultLocale.length + 1) || "/";
|
url.pathname = pathname.slice(defaultLocale.length + 1) || "/";
|
||||||
|
|||||||
Reference in New Issue
Block a user