# Rewrite to lowercase?

**URL:** <https://www.ruby-forum.com/t/rewrite-to-lowercase/182655>\
**Category:** NGINX\
**Created:** [February 1, 2010, 6:27am UTC](https://www.ruby-forum.com/t/rewrite-to-lowercase/182655 "2010-02-01T06:27:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arianna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/91b2a8/32.png) [@arianna](https://www.ruby-forum.com/u/arianna)\
**Post date:** [February 1, 2010, 6:27am UTC](https://www.ruby-forum.com/t/rewrite-to-lowercase/182655/1 "2010-02-01T06:27:50Z")

</div>

can it be done? need case insensitivity on ubuntu

Posted at Nginx Forum:

> **[rewrite to lowercase?](https://forum.nginx.org/read.php?2,48527,48527#msg-48527)**
>
> can it be done? need case insensitivity on ubuntu

---

<div class="post-metadata">

**Author:** ![arianna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/91b2a8/32.png) [@arianna](https://www.ruby-forum.com/u/arianna)\
**Post date:** [February 1, 2010, 2:27pm UTC](https://www.ruby-forum.com/t/rewrite-to-lowercase/182655/2 "2010-02-01T14:27:15Z")

</div>

On 02/01/2010 06:27 AM, arianna wrote:

> can it be done? need case insensitivity on ubuntu

I think the only way this can be done right now is by writing a module  
that  
adjusts the uri according to your needs in the early processing stages.

Regards,  
Dennis

---

<div class="post-metadata">

**Author:** ![arianna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/91b2a8/32.png) [@arianna](https://www.ruby-forum.com/u/arianna)\
**Post date:** [February 17, 2010, 8:59am UTC](https://www.ruby-forum.com/t/rewrite-to-lowercase/182655/3 "2010-02-17T08:59:30Z")

</div>

Hi

I managed to rewrite URLs to lowercase with the embedded perl module:

http {  
…  
perl\_modules perl/lib;

```
perl_set $uri_lowercase 'sub {
    my $r = shift;
    my $uri = $r->uri;
    $uri = lc($uri);
    return $uri;
}';

```

…  
}

server {  
…

location / {  
if ( $uri != $uri\_lowercase ) {  
rewrite . http://$host$uri\_lowercase;  
}

# or just:

# rewrite . $uri\_lowercase;

}  
…  
}

The first option (with the if and http://$host) sends an HTTP redirect  
to the lowercase URL if the requested URL is not completely in  
lowercase. I like this approach better as it kind of normalizes all URL  
to a canonical form. The second option (without if nor http://) just  
accepts any URL and internally rewrites them to lowercase: if you rename  
all your directories and files to lowercase, this will imitate Windows’  
case-insensitive behaviour.

Kudos to the following post were I draw the “inspiration” 😃 from to get  
this done. The embedded perl doc and examples are indeed scarce. ☹

[http://forum.nginx.org/read.php?2,39425,39944](http://forum.nginx.org/read.php?2,39425,39944)

Anyway I see two problems in this approach:

- you need the embedded perl module which according to the docs is  
experimental and can lead to memory leaks.

- the actual redirection is done with the rewrite, which you can put on  
the location you need. But the URL lowercase calculation, being on the  
“http” section of the config, is done for each and every request  
arriving to your server. Say you have a virtual server with 10 domains  
and you only need this on one particular location of one of them. The  
lowercase URL is going to be calculated for every request of every  
domain.

I guess that by defining a perl function the URL calculation could be  
restricted to a particular location, have to look into it further.  
Another option is writing a C module.

Regards

El 01/02/2010, a las 06:27, arianna  
escribió:

> can it be done? need case insensitivity on ubuntu
