Why can't we disable case sensitivity in our URLs?

Note to mods: If this post is in the wrong category, please move it.

I have a website where, on Windows, works fine, no matter if I go to /API or /api, it will always go to the API folder. However, using InfinityFree, we cannot go to a page if the folder is named “API”, and we try to go to “example.com/Api” you will get a 404 error. Why can’t we change this setting? Using the 2 .htaccess rules:

CheckSpelling on
CheckCaseOnly On

does not seem to work at all. Is there a way that this can be toggled? I don’t want to go through my source code for my app to change a good majority of the URLs, which is mainly my fault because it’s tedious. If this could be changed, it would probably benefit a good majority of users who are programming on Windows and use InfinityFree for hosting.

mod_spelling is disabled on these servers because it requires too much server power. I found this script that looks promising:

If you don’t want to go to the website, the code is below (put it in /404.php and set your ErrorDocument for 404 to /404.php) :

if(preg_match("/[A-Z]/", $_SERVER["REQUEST_URI"])){
    header("location:http://" . $_SERVER["HTTP_HOST"] . strtolower($_SERVER["REQUEST_URI"]));
    exit();
}
3 Likes

This seems to work fine, but only with folders that are in the following scheme:

example.com/testpage/test.php

If you have a folder that is in a scheme such as:

example.com/TestPage/Test.php

and try to access it with example.com/Testpage/Test.php, this script will try to look for example.com/testpage/test.php, not TestPage/Test.php (after testing this with my domain)

Sounds like you have some renaming to do in your future.

Because it’s not a setting. It’s an inherent characteristic of the file system (i.e. operating system) being used. Files in Windows are case insensitive, files on Linux are case sensitive. There are fundamental technical differences between the two operating systems which you can’t just turn on or off.

The right way to fix this issue is to fix your broken URLs. And be careful and consistent with casing in your file names and URLs when developing your site.

mod_speling (note the intentional mistype) is a dirty hack for Windows users, and definitely not something that should be relied on a way to correctly operate a web server. On Linux, TestPage.php and testpage.php are different files. Expecting the server to guess which file to load when TESTPAGE.PHP is being requested makes no sense.

Bugs can occur when your development and your live environment are different. To that end, it would be better if you could develop your website on Linux (could you run a LAMP stack in WSL?) so you could avoid these issues.

4 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.