-
Notifications
You must be signed in to change notification settings - Fork 27.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
URL resolution case sensitivity is inconsistent #21498
Comments
I went down the rabbit hole a bit looking into this. I'm pretty sure that the reason for the case-insensitivity is this hard-coded option:
That was originally added in #9157 by @ijjk, specifically in commit 45942a9. I can't find any discussion though in the PR or the RFC #9081 about the case sensitivity of redirects & rewrites, so it seems like an oversight? At least my gut feeling would be that the "right" thing to do here would be to keep redirects as case-insensitive, but make the rewrites case-sensitive. Would a PR for that be welcome? |
I am running into the same issue at work. We have an {
source: '/About',
destination: '/about',
permanent: true,
} sends us into an infinite redirect loop, because Per these discussions, the only available "solution" to this problem right now is to implement redirecting with a dynamic route: (taken from the SO answer)
But this solution seems quite hacky/suboptimal to me. The real problem, I think, is the disparity between resolution & redirect case-sensitivity. Either both should be case-insensitive, or both sensitive. Personally, I enjoy @nbouvrette's suggestion of making resolution case-insensitive & auto-redirecting to the canonically-cased path, but technically that's a compatibility-breaking change--it's possible, though probably very rare (and arguably bad practice anyway) that some sites currently rely on case-insensitive routing to send, e.g., |
Another idea, if we want to avoid the breaking change could be to add a new It would be great to get some feedback from Vercel on this issue. |
I'm having the same issue, is there any feedback about this? Solved it using rewrites {
source: '/(a|A)(b|B)(o|O)(u|U)(t|T)',
destination: '/about',
} |
Thanks! This is by far the best to do it right now imo. I did notice one infinite redirect with this method in my dev testing, but I'm hoping that was a red herring. Agree with above that a setting on capitalization sensitivity would be helpful, but at least for now we can use the rewrite solution very easily. |
I am facing the same issue but with a language path 🤦 We've launched an initial version of a project with Tried both strategies: redirects and rewrites. Both are not working... |
A functionality for automatically lowering URLs would be great, specially for SEO since Google understand that a URL /about is different from /About. |
Same issue as @psoaresbj - super frustrating! |
Works nice for me, thanks a lot |
Hello guys, how can I do this with |
same problem! How to deal with :slug if I need it uppercase? |
Same problem here! |
FYI this goes a bit beyond this issue, but we have resolved most of the current challenges with this solution: https://github.com/Avansai/next-multilingual |
Next.js 12.0 brings a new feature wich can help with this problem. We can use Middleware to add custom routing rules: For example, here's a next.config.js file with support for a few languages. Note the "default" locale has been added intentionally.
This Middleware skips adding the default prefix to API Routes and public files like fonts or images. If a request is made to the default locale, we redirect to our prefix /en. |
Any updates on the issue? Unfortunately still not fixed |
In the pages/_app.js file, I added:
There's probably a more eloquent way to handle this, but this will work for any capitalized url entered. |
This would be great to get a path forward on from Vercel |
I wonder if it slows down the website a little? |
Besides that, it is not a redirect so if you are concerned about SEO better add a specific redirect to next.config.js or add middleware
|
Agree... Just had the issue where the Author changed a slug; /About resulted in a 404, it didn't resolve to the /about page. Possible Solution: OK, we can add a redirect for /About ==> 308 /about |
Any news on this... seems like a pretty major issue. I've got a bunch of urls with mixed casing. |
It would be great if there was something we could put in next.config.js to dynamically redirect urls to lowercase without having to do the middleware hack. |
I was able to solve the issue of locales with rewrites, with this code: // next.config.js
async rewrites() {
return [
{
source: '/([eE][sS]-[eE][cC])/:path*',
destination: '/es-EC/:path*',
locale: false,
},
];
} |
I adjusted this for nextjs slug pages (i.e. [id].js)
|
Same issue here, but I noticed something I didn't see mentioned yet. In the route tree, only leaf nodes are case sensitive. For example, if your url is I reached out to Vercel support initially because I thought this was a build problem with my deployment. They suggested adding some middleware to normalize urls. // src/middleware.ts
import { rewrite } from "@vercel/edge"
export function middleware(request: Request) {
const url = new URL(request.url)
// Don't modify files
// Without this bundled js files and assets (e.g. fonts, images) will break
if (/\.[a-z0-9]+$/i.test(url.pathname)) {
return
}
// Note: we're excluding origin, search, and hash from normalization
const lowerCaseUrl = new URL(
`${url.origin}${url.pathname.toLowerCase()}${url.search}${url.hash}`
)
if (lowerCaseUrl.toString() !== url.toString()) {
// For some reason Vercel rewrite doesn't seem to be working
// rewrite(lowerCaseUrl)
return Response.redirect(lowerCaseUrl.toString())
}
} However, this solution has some problems. For example, this forces any dynamic segment of my url to be lowercased. I would rather a url like I have not tested this using the app directory. |
This is like 2 years old now, is there no better way to do it? |
This adds an experimental `caseSensitiveRoutes` config that currently applies for `rewrites`, `redirects`, and `headers` to change the default of case-insensitive. x-ref: [slack thread](https://vercel.slack.com/archives/C02K2HCH5V4/p1686080359514479?thread_ts=1686077053.623389&cid=C02K2HCH5V4) x-ref: [slack thread](https://vercel.slack.com/archives/C057RG6Q9MX/p1686078875948069?thread_ts=1686077882.133609&cid=C057RG6Q9MX) x-ref: #21498
I am still facing same issue. i have a page in App directory i.e App/About/page.tsx domain.com/About works but domain.com/about results in 404. How to fix it? |
This adds an experimental `caseSensitiveRoutes` config that currently applies for `rewrites`, `redirects`, and `headers` to change the default of case-insensitive. x-ref: [slack thread](https://vercel.slack.com/archives/C02K2HCH5V4/p1686080359514479?thread_ts=1686077053.623389&cid=C02K2HCH5V4) x-ref: [slack thread](https://vercel.slack.com/archives/C057RG6Q9MX/p1686078875948069?thread_ts=1686077882.133609&cid=C057RG6Q9MX) x-ref: vercel#21498
I am facing a similar issue as well, and the answers from above did not work in my case. I see some new commits have been pushed towards this case, so any idea when the experimental caseSensitiveRoutes will be available? I have my issue described here, if anyone came across it as well https://stackoverflow.com/questions/76605645/nextjs-uppercase-locales-redirect-to-lowercase . Thank you! |
You can try using it using the experimental version: // next.config.js
// @ts-check
/**
* @type {import('next').NextConfig}
**/
const nextConfig = {
/* config options here */
experimental: {
caseSensitiveRoutes: true
}
}
module.exports = nextConfig |
It does not work unfortunately, but thank you! |
This is such a major issue. I was running the app locally on my machine and it worked fine. I'm using Windows so it worked fine. Windows deals with it internally. I later asked about this online and was told that Vercel deployment uses Linux which is case-sensitive. So when I was trying to go to About it was not working sadly. Also, what about cases like AbouT, ABOUT, AbOUT, and all other cases? It should be case insensitive to handle all these cases too. Am I right? |
Creates rewrites for redirect loop, as case sensitivity in Next.js is inconsistent (see also vercel/next.js#21498 (comment)). Background: Sometimes you want a redirect from an uppercase to a lowercase URL (e.g. /Example to /example) for SEO purposes. This can be created in our admin without problems. The casing is saved correctly in the DB and transferred to Next. The problem is that this creates a redirect loop in the site. The reason is that the case sensitivity of Next.js is inconsistent. The delivery of pages is case sensitive. The redirects are case insensitive: Without redirect: http://localhost:3000/example -> page is delivered http://localhost:3000/Example -> 404 With redirect: http://localhost:3000/example -> Redirect to /example -> Loop http://localhost:3000/Example -> Redirect to /example -> Loop Also described here: vercel/next.js#21498 --------- Co-authored-by: Johannes Obermair <[email protected]>
Creates rewrites for redirect loop, as case sensitivity in Next.js is inconsistent (see also vercel/next.js#21498 (comment)). --- Background: Sometimes you want a redirect from an uppercase to a lowercase URL (e.g. `/Example` to `/example`) for SEO purposes. This can be created in our admin without problems. The casing is saved correctly in the DB and transferred to Next. The problem is that this creates a redirect loop in the site. The reason is that the case sensitivity of Next.js is inconsistent. The delivery of pages is case sensitive. The redirects are case insensitive: Without redirect: http://localhost:3000/example -> page is delivered http://localhost:3000/Example -> 404 With redirect: http://localhost:3000/example -> Redirect to /example -> Loop http://localhost:3000/Example -> Redirect to /example -> Loop Also described here: vercel/next.js#21498 --------- Co-authored-by: Thomas Dax <[email protected]>
Creates rewrites for redirect loop, as case sensitivity in Next.js is inconsistent (see also vercel/next.js#21498 (comment)). --- Background: Sometimes you want a redirect from an uppercase to a lowercase URL (e.g. `/Example` to `/example`) for SEO purposes. This can be created in our admin without problems. The casing is saved correctly in the DB and transferred to Next. The problem is that this creates a redirect loop in the site. The reason is that the case sensitivity of Next.js is inconsistent. The delivery of pages is case sensitive. The redirects are case insensitive: Without redirect: http://localhost:3000/example -> page is delivered http://localhost:3000/Example -> 404 With redirect: http://localhost:3000/example -> Redirect to /example -> Loop http://localhost:3000/Example -> Redirect to /example -> Loop Also described here: vercel/next.js#21498 --------- Co-authored-by: Thomas Dax <[email protected]>
I've resolved the issue by adding a middleware function which is the first one in the middleware chain.
|
What version of Next.js are you using?
10.0.5
What version of Node.js are you using?
14.15.0
What browser are you using?
Chrome
What operating system are you using?
Windows
How are you deploying your application?
Local
Describe the Bug
File system routes
http://localhost:3000/about -> renders pages/about.js
http://localhost:3000/ABOUT -> 404 not found
Result: case sensitive.
Redirects
Using this example: https://github.com/vercel/next.js/tree/canary/examples/redirects
http://localhost:3000/team -> redirects to /about -> renders pages/about.js
http://localhost:3000/TEAM -> redirects to /about -> renders pages/about.js
Result: case insensitive.
Rewrite
Using this example: https://github.com/vercel/next.js/tree/canary/examples/rewrites
http://localhost:3000/team -> rewrites to /about -> renders pages/about.js
http://localhost:3000/TEAM -> rewrites to /about -> renders pages/about.js
Result: case insensitive.
Expected Behavior
All URL resolution should have a consistent default behavior
Proposal:
Benefits:
To Reproduce
See description - make sure to open each URL in a new incognito window to avoid Chrome cache hits.
The text was updated successfully, but these errors were encountered: