It looks that by default Next.js handles URLs in a case-insensitive manner (at least when using rewrites).
I found this documentation on redirects
and was wondering if there is a way to do a global redirect if a URL is found with capital letters, to its equivalent lowercase letter URL?
Is there a way to do this either with redirects or some other way? (ideally looking for a global solution)
Here is a pseudo-code (non-functional) of what I had in mind (this would be in next.config.js
):
module.exports = {
async redirects() {
return [
{
source: '/:url*(p{Alphabetic})',
destination: `/${url.toLocaleLowerCase()}`,
permanent: true,
},
];
}
};
question from:
https://stackoverflow.com/questions/65863016/next-js-global-redirect-to-lowercase-urls 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…