WeLoveCSS Logo
Home Profile Members Search Rules Help New Posts

WeLoveCSS > SOCIAL CHAT > Resources > Converting URLs to lowercase

  Thread Tools Display Modes
Old 27th May 10, 06:51 AM   #1
meesa's Avatar
Join Date: Jul 2009
Location: Milky Way Galaxy
Posts: 3,716
Default Converting URLs to lowercase

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:
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:

<script type="text/javascript">
var URL=document.location;
//This makes the URL become a string, without it, an error would

if(URL.toLowerCase() != URL){ //Check if the URL needs modified
//If so, then replace it.

//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.
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.

Last edited by meesa; 4th March 11 at 10:50 PM.
meesa is offline   Reply With Quote

Thread Tools
Display Modes
Linear Mode Linear Mode

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 09:11 AM.

Home | Advertise | Contact Us | Top
Home | Advertise | Contact Us | Top

Copyrightę 2006 WeLoveCSS.com. All Rights Reserved.
Powered by vBulletin Version 3.8.4 Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.