]> git.kaiwu.me - nginx.git/commitdiff
fix a try_files/alias case when alias uses captures and
authorIgor Sysoev <igor@sysoev.ru>
Thu, 27 May 2010 13:44:22 +0000 (13:44 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Thu, 27 May 2010 13:44:22 +0000 (13:44 +0000)
     try_files  .html  ""  /  =404;

src/http/ngx_http_core_module.c
src/http/ngx_http_request.h

index a91d5854b8ddf4ddf2fc042b2df613912c23a0c4..f7c44849c326dd4102c6bab5ec9fa92b9a119b2a 100644 (file)
@@ -1286,6 +1286,7 @@ ngx_http_core_try_files_phase(ngx_http_request_t *r,
         } else if (clcf->regex) {
             if (!test_dir) {
                 r->uri = path;
+                r->add_uri_to_alias = 1;
             }
 #endif
         } else {
@@ -1783,7 +1784,9 @@ ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
         ngx_uint_t  captures;
 
         captures = alias && clcf->regex;
-        reserved += captures ? 1 : r->uri.len - alias + 1;
+
+        reserved += captures ? r->add_uri_to_alias ? r->uri.len + 1 : 1
+                             : r->uri.len - alias + 1;
 #else
         reserved += r->uri.len - alias + 1;
 #endif
@@ -1804,8 +1807,12 @@ ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
 
 #if (NGX_PCRE)
         if (captures) {
-            *last = '\0';
-            return last;
+            if (!r->add_uri_to_alias) {
+                *last = '\0';
+                return last;
+            }
+
+            alias = 0;
         }
 #endif
     }
@@ -2213,6 +2220,7 @@ ngx_http_internal_redirect(ngx_http_request_t *r,
 #endif
 
     r->internal = 1;
+    r->add_uri_to_alias = 0;
     r->main->count++;
 
     ngx_http_handler(r);
index f9622714c5b86432d74ce39be70eff6229c46a00..0559b46502f1d7b7c750cb6c2da62673d9519f14 100644 (file)
@@ -437,6 +437,7 @@ struct ngx_http_request_s {
 
     unsigned                          invalid_header:1;
 
+    unsigned                          add_uri_to_alias:1;
     unsigned                          valid_location:1;
     unsigned                          valid_unparsed_uri:1;
     unsigned                          uri_changed:1;