how to redirect user from handler

Anatoli Marinov toli at
Thu Sep 20 09:12:58 UTC 2012

Hello Colleagues,
Which is the right way to redirect user request from handler module. Now 
I have something like this in my handler:

My handler function(r) {
     header = ngx_list_push(&r->headers_out.headers);
     header->key.len = sizeof("Location") - 1;
     header-> = (u_char *) "Location";

     header->value.len = strlen("");
     header-> = ngx_pcalloc(r->pool, header->value.len);

     ngx_snprintf(header->, header->value.len, "%s", 
     r->headers_out.status = NGX_HTTP_MOVED_TEMPORARILY;
     r->chunked = 0;


     return NGX_DECLINED;

I think this approach is wrong. It sends 302 to the client but there is 
a body with 404 return code which is not correct.

So please advise me how to redirect from hander.

Thanks in advance
Anatoli Marinov

More information about the nginx-devel mailing list