Search code examples
http-redirecturl-rewritinglighttpd

Lighttpd Redirect url to Lowercase Version


I am using lighttpd, and I would like to redirect uppercase urls to lowercase.

For example, if I have the following url: http://test.com/info/code/BDAY

I would like to redirect it to: http://test.com/info/code/bday

What is the best way to go about doing this?


Solution

  • Lighttpd's internal mod_rewrite and mod_redirect can only handle pattern matching and substitution, they are unable to do character translation.

    You could have a pattern which matches any uppercase character and passes the URL to a script that does the rewrite and returns a redirect

    lighttpd.conf:

    url.rewrite-once += ( "(.*[A-Z].*)" => "lower.php?url=$1" )
    

    lower.php:

    <?php header("Location: " + strtolower($_GET['url']));