diff options
Diffstat (limited to 'src/http/ngx_http_core_module.c')
-rw-r--r-- | src/http/ngx_http_core_module.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 529f2ee27..f4f5d4f3c 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -369,16 +369,27 @@ static void ngx_http_run_phases(ngx_http_request_t *r) int ngx_http_find_location_config(ngx_http_request_t *r) { int i, rc; + ngx_str_t *auto_redirect; ngx_http_core_loc_conf_t *clcf, **clcfp; ngx_http_core_srv_conf_t *cscf; cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); + auto_redirect = NULL; clcfp = cscf->locations.elts; for (i = 0; i < cscf->locations.nelts; i++) { #if 0 ngx_log_debug(r->connection->log, "trans: %s" _ clcfp[i]->name.data); #endif + if (clcfp[i]->auto_redirect + && r->uri.len == clcfp[i]->name.len - 1 + && ngx_strncmp(r->uri.data, clcfp[i]->name.data, + clcfp[i]->name.len - 1) == 0) + { + auto_redirect = &clcfp[i]->name; + continue; + } + if (r->uri.len < clcfp[i]->name.len) { continue; } @@ -386,6 +397,7 @@ ngx_log_debug(r->connection->log, "trans: %s" _ clcfp[i]->name.data); rc = ngx_strncmp(r->uri.data, clcfp[i]->name.data, clcfp[i]->name.len); if (rc < 0) { + /* locations are lexicographically sorted */ break; } @@ -406,6 +418,22 @@ ngx_log_debug(r->connection->log, "trans: %s" _ clcfp[i]->name.data); r->sendfile = 1; } + if (auto_redirect) { + if (!(r->headers_out.location = + ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) + { + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + +#if 0 + r->headers_out.location->key.len = 8; + r->headers_out.location->key.data = "Location"; +#endif + r->headers_out.location->value = *auto_redirect; + + return NGX_HTTP_MOVED_PERMANENTLY; + } + if (clcf->handler) { /* * if the location already has content handler then skip |