Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have nginx setup, however I'm needing to fix an issue where someone types "/Home" to:

  • rewrite it to the lowercase "/home" (do this to all files and directories, not just home) but locate the Uppercase (if there is one) file.
  • Or do I need to add another location that uses the case-insensitive characters "~*" ?

The actual directory and file layout does contain mixed Upper and lower case characters. I would like to preserve this for simplicity sake, i.e. /Home and /About are the actual directories, but for SEO I want to permanent redirect to the lowercase /home but find the actual /Home directory.

I'm not sure if this can be accomplished by a rewrite rule or if there is a case insensitivity on the "location / { }" or some combination.

        location / {
                try_files $uri $uri/ /Home;

Note: I'm not looking for answers that fall into Nginx Pitfalls, including the evil Ifs.

share|improve this question
One option is to use an additional location block that matches any upper case characters, and contains a rewrite to the lowercase uri. You can perform the string manipulation needed using the embedded perl module (e.g. like this) – cyberx86 Apr 18 '12 at 2:33

As mentioned in comments to your question, this is possible by use of perl module. Assuming you'll use that $uri_lowercase you may write something like this:

location / {
    try_files $uri $uri/ $uri_lowercase $uri_lowercase/ =404;

Note however that $uri_lowercase may not fit your needs if you have mixed case URLs like /Home/UseR/teSt.html and you need to try all bunch of partially lowercased uri. If this is your case i strongly advice to get some policy on your directories and require them to be lowercase.

share|improve this answer
Yeah, I'm trying to make it easier for dev's in how they currently work and having to not rename a bunch of files and directories. Basically a uri of /Home to do a permanent redirect to /home, but have the /home match the physical /Home directory? Make sense? Kind of stupid, but going for SEO and moving from MSFT website to Linux. From what you've provided (I'll double check) it looks like uri of /home will not match the physical dir /Home – thames Apr 18 '12 at 15:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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