Reproducing the issue where Next.js middleware receives URLs with pathnames already normalized to lowercase, preventing uppercase-to-lowercase redirects.
When accessing /en-US, the middleware should receive the original casing to redirect to/en-us. However,req.url andreq.nextUrl.pathnamealready contain the lowercase version.
Click these links and check the browser console + terminal for middleware logs:
const lowercaseUrl = new URL(req.url);
const path = lowercaseUrl.pathname;
if (path !== path.toLowerCase()) {
lowercaseUrl.pathname = path.toLowerCase();
return NextResponse.redirect(lowercaseUrl.toString(), 308);
}Check the terminal running the dev server to see the middleware logs.