views:

226

answers:

2

This seems like it should be an easy thing to do, but for the life of me I can't figure this out.

I want to force my entire URL to be in lower case, so that, for example:

http://www.EXAMPLE.com/foo?q=bar
http://www.example.com/FOO?q=bar
http://www.example.com/foo?Q=BAR
http://www.EXAMPLE.com/FOO?Q=BAR

all (301) redirect to:

http://www.example.com/foo?q=bar

Adding:

RewriteMap  lc int:tolower

to httpd.conf, and:

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

to .htaccess, I can make the base part of the URL redirect the way I want (the first two cases above), but I can't figure out how to make this work with for the query string. Can anyone point me in the direction of how to do this?

A: 

Give this a shot, I didn't test it:

RewriteMap lowercase int:tolower
RewriteCond $1 [A-Z]
RewriteRule ^/(.*)$ /${lowercase:$1} [R=301,L]
Sean A.O. Harney
Thanks. I also tried this but it didn't help.
Anonymous Coward
A: 

Try this rule:

RewriteCond %{REQUEST_URI} ^[^A-Z]*[A-Z].* [OR]
RewriteCond %{QUERY_STRING} ^[^A-Z]*[A-Z].*
RewriteRule ^ ${lc:%{REQUEST_URI}}?${lc:%{QUERY_STRING}} [L,R=301]
Gumbo
That does it. Thanks Gumbo!
Anonymous Coward