View Full Version : redirect a wong url to his lower case version

12-24-2002, 02:35 AM
for example, if the user writes http://myurl.com/TheFolder and it doesn't exist, redirect to http://myurl.com/thefolder. I can do it using javascript in the 404.shtml page, but I'm sure that there is a better & more intelligent way

My server uses Apache. "Answer for dummies" please, I'm not very familiar with Apache & server languages / includes

12-27-2002, 09:04 PM
Well, seems that it can't be done. It was a nice idea :(

01-04-2003, 11:07 AM
The best option is mod_spelling (http://httpd.apache.org/docs/mod/mod_speling.html), which will allow you to ignore case and have up to 'one misspelling' in a URL. It may be beyond your skills or access to the box, however. If it is already installed, try just sticking CheckSpelling on in an htaccess file for your site.

Or you could make it conditional by checking to see if mod_spelling is available, and if it is turn it on:

<IfModule mod_speling.c>
Checkspelling on

You could do it (though not truly) through mod_rewrite in htaccess, but it would be pretty inefficient and be too heavy for what I would want to use...but it is doable.

The real reasons you can't do it is that regex and substitution patterns need a per character pattern. Second, making them all upper or all lower case dynamically will not really help with case insensitive URLs, because the case that is typed in must access the case as it exists in the file-system (and making it all lc or all uc will not necessarily get the filename as it truly exists). Mod-spelling is the best way to go.

Like I said, you could do it through mod_rewrite, but it would be extremely heavy and nasty...it would perform this extremely heavy and nasty check with EVERY SINGLE FILE ACCESS on your site (though you could make it semi-smart and order it not to check certain file types, but what about the case sensitivity of those file types?).

The real and best way is to use all lowercase for your directories and file names, period.

01-04-2003, 03:54 PM
Ok thanks I will take a look at it

In fact the situation is the following:
I have a domain and offer a free subfolder for the customers that don't want to buy a domain name:

..and so on

So if somebody writes i.e. RamblaBar, RAMBLABAR or RaMbLaBaR, I want the sistem to lowercase it (as I always use lowercase) and see if it exist, no need to check all the site looking for the specific file

Now I'm using this javascript for the 404 page:
errurl='<!--#echo var="REQUEST_URI" -->'
if (errurl!=corrurl) {self.location=corrurl} else {document.write('Error 404')}

It works fine, but don't looks very "professional" ;)