Case sensitivity with redirects

Hey everyone,

Are redirects listed in _redirects case-sensitive?

I’m having a minor issue with redirects.

The following URL redirects to twitter.com:
https://clever-benz-7901c5.netlify.com/twitter

However, the redirect completely fails if I type my URL in a different way:
https://clever-benz-7901c5.netlify.com/TWITTER

This is the exact code I’m using:
/twitter https://twitter.com

Am I missing something? I have Pretty URLs enabled.

Thanks!

1 Like

The path component of an HTTP URL is case-sensitive; this is part of the standard. Thus, /twitter and /TWITTER are two different URLs, and you need to decide what you will serve (content, 404, etc.) for each one. A site might serve the same for both, but that would be a choice of the site developer.

As a side note, Netlify itself may do some case-changing for built-in redirections. I think I’ve even seen this with pretty URLs disabled (something like getting /Foo:Bar, redirecting it to /foo:bar and then serving /Foo:Bar.html for it) but I don’t recall all the details now.

2 Likes

Is there any way to case-change all URLs using Netlify’s built-in redirections?

That’s a great answer @cjs, thanks!

When you use redirects, we don’t change the case and it is case-sensitive. If you need to match multiple cases then you’ll have to include separate redirect lines for each of those cases.

@futuregerald and @cjs I totally understand and appreciate that it’s the developer’s choice. As the developer on an app, I’d like to be able to choose if something is case insensitive. Being able to use regex would be great.

Well, you don’t get to choose that the HTTP standard specifies that URL paths are case-sensitive and all clients adhere to that (e.g., browsers will treat differences in case as separate URLs for the purposes of caching, bookmarks, etc.). I’d strongly suggest you just go with case-sensitivity for your app as well, because trying to buck the standard is likely to lead only to problems. If you absoutely need to treat all possible case variations of a URL the same, you probably want to build your own platform for serving this rather than using Netlify.