commit c85551c01a9f36f324c0d9ac7925a2b55eb2f614 Author: Kirill A. Korinskiy Date: Tue Jul 28 16:56:30 2009 +0400 Add support rewrite to named location diff --git a/src/http/modules/ngx_http_rewrite_module.c b/src/http/modules/ngx_http_rewrite_module.c index d9482e6..25e98a3 100644 --- a/src/http/modules/ngx_http_rewrite_module.c +++ b/src/http/modules/ngx_http_rewrite_module.c @@ -352,6 +352,11 @@ ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) last = 1; } + if (value[2].data[0] == '@') { + regex->named_redirect = 1; + last = 1; + } + if (cf->args->nelts == 4) { if (ngx_strcmp(value[3].data, "last") == 0) { last = 1; @@ -439,6 +444,7 @@ ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) regex_end->args = regex->args; regex_end->add_args = regex->add_args; regex_end->redirect = regex->redirect; + regex_end->named_redirect = regex->named_redirect; if (last) { code = ngx_http_script_add_code(lcf->codes, sizeof(uintptr_t), ®ex); diff --git a/src/http/ngx_http_script.c b/src/http/ngx_http_script.c index 680d8e3..44dd9e5 100644 --- a/src/http/ngx_http_script.c +++ b/src/http/ngx_http_script.c @@ -994,6 +994,14 @@ ngx_http_script_regex_end_code(ngx_http_script_engine_t *e) ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http script regex end"); + if (code->named_redirect) { + ngx_http_named_location(r, &e->buf); + r->err_status = 0; + e->status = NGX_DONE; + e->ip += sizeof(ngx_http_script_regex_end_code_t); + return; + } + if (code->redirect) { dst = e->buf.data; diff --git a/src/http/ngx_http_script.h b/src/http/ngx_http_script.h index 3ce72aa..1348a75 100644 --- a/src/http/ngx_http_script.h +++ b/src/http/ngx_http_script.h @@ -130,6 +130,7 @@ typedef struct { uintptr_t add_args:1; uintptr_t redirect:1; + uintptr_t named_redirect:1; uintptr_t break_cycle:1; ngx_str_t name; @@ -146,6 +147,7 @@ typedef struct { uintptr_t add_args:1; uintptr_t redirect:1; + uintptr_t named_redirect:1; } ngx_http_script_regex_end_code_t; #endif