preventing rewrite loops with "index"

Dennis J. dennisml at conversis.de
Fri Jan 22 17:06:47 MSK 2010


Hi,
So with my first rewrite issue solved I now move closer towards the real 
configuration and run into a problem with the index directive.

My location looks like this:

location ~* ^/(([A-Za-z])([A-Za-z0-9])([A-Za-z0-9])[^/]*)(/.*)?$ {
     root /web;
     set $site_path /users/$2/$3/$4/$1/htdocs;
     set $real_uri $5;
     rewrite .* $site_path$real_uri break;
}

When I request "/test/index.html" the location matches and gets properly 
rewritten into a hashed form "/users/t/e/s/test/index.html". Then the root 
get prefixed resulting in the path "/web/users/t/e/s/test/index.html" which 
get correctly delivered by nginx. So far so good.

The problem happens when I request "/test/" instead which should deliver 
the same index.html through the index directive. That doesn't happen though.

Looking at the log what seems to happen is that nginx sees that 
"/web/users/t/e/s/test/" is a directory and issues a new request with the 
uri "/web/users/t/e/s/test/index.html". This however matches the above 
location again resulting in another rewrite that ends with a completely 
broken path and a 404.

How can I get that the correct index processing for the first correctly 
rewritten path without triggering another round of location processing 
messing things up?

Regards,
   Dennis



More information about the nginx mailing list