diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index c75ddb849..0915c4866 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -1045,6 +1045,8 @@ ngx_http_core_find_config_phase(ngx_http_request_t *r, ngx_memcpy(p, r->args.data, r->args.len); } + r->request_auto_redirect = 1; + ngx_http_finalize_request(r, NGX_HTTP_MOVED_PERMANENTLY); return NGX_OK; } diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h index ad11f147f..c982635da 100644 --- a/src/http/ngx_http_request.h +++ b/src/http/ngx_http_request.h @@ -545,6 +545,7 @@ struct ngx_http_request_s { unsigned error_page:1; unsigned filter_finalize:1; unsigned post_action:1; + unsigned request_auto_redirect:1; unsigned request_complete:1; unsigned request_output:1; unsigned header_sent:1; diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c index 4f0bd0e4b..582608384 100644 --- a/src/http/ngx_http_variables.c +++ b/src/http/ngx_http_variables.c @@ -93,6 +93,8 @@ static ngx_int_t ngx_http_variable_body_bytes_sent(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); static ngx_int_t ngx_http_variable_pipe(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); +static ngx_int_t ngx_http_variable_request_auto_redirect(ngx_http_request_t *r, + ngx_http_variable_value_t *v, uintptr_t data); static ngx_int_t ngx_http_variable_request_completion(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); static ngx_int_t ngx_http_variable_request_body(ngx_http_request_t *r, @@ -284,6 +286,10 @@ static ngx_http_variable_t ngx_http_core_variables[] = { { ngx_string("pipe"), NULL, ngx_http_variable_pipe, 0, 0, 0 }, + { ngx_string("request_auto_redirect"), NULL, + ngx_http_variable_request_auto_redirect, + 0, 0, 0 }, + { ngx_string("request_completion"), NULL, ngx_http_variable_request_completion, 0, 0, 0 }, @@ -2088,6 +2094,20 @@ ngx_http_variable_set_limit_rate(ngx_http_request_t *r, } +static ngx_int_t +ngx_http_variable_request_auto_redirect(ngx_http_request_t *r, + ngx_http_variable_value_t *v, uintptr_t data) +{ + if (r->request_auto_redirect) { + *v = ngx_http_variable_true_value; + return NGX_OK; + } + + *v = ngx_http_variable_null_value; + return NGX_OK; +} + + static ngx_int_t ngx_http_variable_request_completion(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data)