We have an XMCloud application using NextJs, which we are deploying to Vercel. On the Vercel side, it is working fine. We have a requirement where if someone is adding uppercase/Camelcase in the URLs or a single/multiple uppercase chars in the URL client wants it to redirect to lowercase. see below example -
- https://mydomain.com/AboutUs -> https://mydomain.com/aboutus
- https://mydomain.com/Aboutus -> https://mydomain.com/aboutus
- https://mydomain.com/ABOUTUS-> https://mydomain.com/aboutus
- https://mydomain.com/ABOUtus -> https://mydomain.com/aboutus
Since this is the next 12.3 application, I tried updating the code into middleware like this -
if (req.nextUrl.pathname !== req.nextUrl.pathname.toLowerCase()) {
const url = req.nextUrl.clone()
url.pathname = url.pathname.toLowerCase()
url.href = url.href.toLowerCase();
url.locale = req.nextUrl.locale;
return NextResponse.redirect(url)
}
the above code is working fine locally with connected mode but on vertical it is changing the URL into lowercase but at the same time refreshing the page again and again in 2-3 seconds (infinite times). Anyone please provide some insight on this issue?