I would like redirect a URL with uppercase characters http://localhost/A/B to a lowercase version http://localhost/a/b using the .htaccess file.

Using regex I can capture A and B but is it possible to convert them to lowercase?

link|improve this question

75% accept rate
feedback

1 Answer

up vote 3 down vote accepted

In .htaccess

<IfModule mod_speling.c>
CheckSpelling on
</IfModule>

Tested, works, if you have the mod_speling enabled.

Or, in a serverwide httpd.conf:

RewriteEngine On
RewriteMap  lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]

From: http://www.chrisabernethy.com/force-lower-case-urls-with-mod_rewrite/

link|improve this answer
he specifically said using .htaccess ! you should had read the comments before even copying the link. – Prix Sep 3 '10 at 9:10
Indeed, well spotted. My answer will cause a server error in an .htaccess file. :o – Grizly Sep 3 '10 at 9:28
oops! I was about to jump in joy looking at Grizly's reply :-( – tintin Sep 3 '10 at 9:33
Added a working .htaccess version.. ;-) Of course, if you don't have access to httpd.conf, you probably won't have access to load the speling module.. will only lowercase if the folder/file is in lowercase on filesystem. – Grizly Sep 3 '10 at 10:43
Yup it's working Grizly, thanks a million! – tintin Sep 3 '10 at 13:24
show 1 more comment
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.