How to make a redirect via programming?

Maxim Dounin mdounin at mdounin.ru
Thu May 26 12:03:26 MSD 2011


Hello!

On Wed, May 25, 2011 at 06:41:46PM -0400, speedfirst wrote:

> Hey, I'm making a custom module and need to send back the redirect
> response to the client. It should behave like the "sendRedirect" in java
> servlet programming. So which function is that API?
> 
> Thanks.

    r->headers_out.location = ngx_palloc(r->pool, sizeof(ngx_table_elt_t));
    if (r->headers_out.location == NULL) {
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
    }

    r->headers_out.location->value.len = sizeof("http://example.com/") - 1;
    r->headers_out.location->value.data = "http://example.com/";

    return NGX_HTTP_MOVED_PERMANENTLY;

Maxim Dounin



More information about the nginx mailing list