Internalization and SEO
Unanswered
Blue orchard bee posted this in #help-forum
Blue orchard beeOP
Hi. Please help me solve the problem with internalization and SEO.
I developed a website on Next js using Sanity CMS. AppRouter technology. My website supports English add German languages. The thing is that there is no home page on the main domain, because the folder structure is as follows: app/[lang]/page.tsx. Accordingly, the home page is always located at mysite.com/en or mysite.com/de based on middleware file. Is it possible to somehow reconfigure the project so that the home page is located at mysite.com without a slash? Or is it okay to create project with this structure?
SEO-specialist says that the main language should be on the main domain without subfolders. Who is right in this case?
I have set up internalization this way:
I developed a website on Next js using Sanity CMS. AppRouter technology. My website supports English add German languages. The thing is that there is no home page on the main domain, because the folder structure is as follows: app/[lang]/page.tsx. Accordingly, the home page is always located at mysite.com/en or mysite.com/de based on middleware file. Is it possible to somehow reconfigure the project so that the home page is located at mysite.com without a slash? Or is it okay to create project with this structure?
SEO-specialist says that the main language should be on the main domain without subfolders. Who is right in this case?
I have set up internalization this way:
// middleware.ts
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { i18n } from "@/i18n.config";
import { match as matchLocale } from "@formatjs/intl-localematcher";
import Negotiator from "negotiator";
function getLocale(request: NextRequest): string | undefined {
const negotiatorHeaders: Record<string, string> = {};
request.headers.forEach((value, key) => (negotiatorHeaders[key] = value));
const locales: string[] = i18n.languages.map(lang => lang.id);
const languages = new Negotiator({ headers: negotiatorHeaders }).languages();
const locale = matchLocale(languages, locales, i18n.base || "id");
return locale;
}
export function middleware(request: NextRequest) {
const pathname = request.nextUrl.pathname;
const pathnameIsMissingLocale = i18n.languages.every(
locale =>
!pathname.startsWith(/${locale.id}/) && pathname !==/${locale.id});
if (pathnameIsMissingLocale) {
const locale = getLocale(request);
return NextResponse.redirect(
new URL(/${locale}${pathname.startsWith("/") ? "" : "/"}${pathname},
request.url
)
);
}
}
};