Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
798 views
in Technique[技术] by (71.8m points)

Next.js global redirect to lowercase URLs

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It does not appear that such feature exists, but ultimately this type of feature might be better resolved by fixing this issues documented here: https://github.com/vercel/next.js/issues/21498

There might be other reasons for more advanced URL manipulation and this might become a feature request at some point if the community needs this.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...