I've recently come across the problem of an uppercase URL when you need it to be lowercase to be valid. As most people, I was on a Linux server, and Linux is case sensitive.

So after quite a bit of looking around, I found a couple solutions. None worked. These included the .htaccess/httpd.conf hacks.

Then I hit this nice little comment:

Quote:

You COULD, if you were a stud programmer, make your 404 file actually be a cgi script which reads in the environment variable for the URL it is at, and then lower cases it, and checks if the lower-case version exists, and if so, redirects you there, and if not, outputs a 404 page.

The idea had briefly crossed my mind before, but this comment made me try making something; no, not a CGI script, why bother when there is Javascript?

So I put this nice little script in the 404 page so that it's the first thing that happens before it loads:

Code:

<script type="text/javascript">
var URL=document.location;
//This makes the URL become a string, without it, an error would
//occur.
URL+="";
if(URL.toLowerCase() != URL){ //Check if the URL needs modified
//If so, then replace it.
document.location.replace(URL.toLowerCase());
//I used replace because I didn't want the user to hit the
//back button and then hit the URL that they came from, thus
//returning them to the same place.
}
</script>

That's it, simple and quick! Now as long as your directories and filenames are lowercase, you don't have to worry about somebody mistyping with an uppercase.
Comments or suggestions appreciated.

__________________
Praise be to the Lord God for the ability to learn, the capability to analyze, and the time to help users on this forum.