Forum Moderators: phranque

Message Too Old, No Replies

.htaccess - Total Case - Insensitivity

to make all calls to server case insensitive

         

silentway

2:17 am on Jun 10, 2004 (gmt 0)

10+ Year Member



Hello. I have been searching around for a few hours, and have not been able to find anything that's a quick fix.

i have some web pages whose file names are something like
[site.com...]
and I want the page to be served up if someone types
[site.com...] - - essentially, I want
the server to ignore case.

i think the answer has something to do with mod_rewrite, but
so far, i've only found the ability to hard-code all A's to a.
or the mod_speling which only looks for one mistype.

If you know of the fix for this, I'd appreciate it. Or if you can point me in the direction of a creative solution, also obliged.

Thank you

jdMorgan

2:23 am on Jun 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



silentway,

Welcome to WebmasterWorld [webmasterworld.com]!

If you have access to httpd.conf, you can use RewriteMap to do a tolower on all URLs. Unfortunately, this capability is not available in per-directory .htaccess context, so therefore the interest in the one-by-one substitution that you found.

Jim

silentway

2:47 am on Jun 10, 2004 (gmt 0)

10+ Year Member



Hi, thanks for the reply.

When you say that it's not available in per-directory context, what does that mean?

I'll do some research now on what 'tolower' is.

Thanks.

silentway

3:01 am on Jun 10, 2004 (gmt 0)

10+ Year Member



One more thing..., I see that tolover converts upper to lower... i understand that this will work if a File.html is requested and I have file.html ... but will it also work if file.html is requested and I have File.html?

Thanks

jdMorgan

3:04 am on Jun 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



tolower and toupper are case-conversions to all-lowercase and to all-uppercase, respectively.

"Not available in per-directory context" means not available in .htaccess.

See the RewriteMap description in the mod_rewrite documentation for an example of a tolower call.

Apache mod_rewrite documentation [httpd.apache.org]
Apache URL Rewriting Guide [httpd.apache.org]
Regular Expressions Tutorial [etext.lib.virginia.edu]

If you cannot change your site to use all-lowercase (or all-uppercase) links and filenames, then an alternative would be to to use a tolower RewriteMap first, and then create a second RewriteMap that maps the resulting all-lowercase URLs to your mixed-case URLs. This would require a map entry for each existing URL, but would prevent the huge problem of having to handle all possible case-mixing variants of your URLs. Then going forward, use all-lowercase links and URLs so that this problem does not grow. In order to avoid running the RewriteMap for every requested URL, you could then preface the ruleset with


RewriteCond %{REQUEST_URI} [A-Z]

which would require that the requested URL contain at least one uppercase character before the RewriteRule would be invoked. This would probably improve overall server performance as you moved toward more and more all-lowercase URLs and links.

Jim