By default, Nextjs route is case sensitive. Is there any way we can make it case insensitive?

28 Views Asked by At

I am using app router here. The current URL I have is http://localhost:3000/SomeClientURL

But the ask from client is if user enter http://localhost:3000/someclienturl it should work the same way.

I was trying with below rewrites method but didn't work.

const nextConfig = {
  basePath: "/SomeClientURL",
  async rewrites() {
    return [
      {
        source: '/someclienturl',
        destination: '/SomeClientURL',
      },
    ]
  },
  sassOptions: {
    ..someSettingsHere
  },
  images: {
   ..someSettingsHere
  },
};

1

There are 1 best solutions below

0
Youssouf Oumar On

If you were, I would name all my route files in lowercase, and use a middleware to implement case insensitivity

// middleware.js at the same level as app or pages folder

import { NextResponse } from "next/server";

export function middleware(request) {
  return NextResponse.rewrite(new URL(request.nextUrl.pathname.toLocaleLowerCase(), request.url));
}