HTTPServerResponseData.redirect

Sends a redirect request to the client.

  1. void redirect(string url, int status)
    struct HTTPServerResponseData
    protected @safe @safe
    void
    redirect
    (
    string url
    ,
    int status = HTTPStatus.Found
    )
  2. void redirect(URL url, int status)

Parameters

url string

The URL to redirect to

status int

The HTTP redirect status (3xx) to send - by default this is HTTPStatus.found

Examples

import vibe.http.router;

void request_handler(HTTPServerRequest req, HTTPServerResponse res)
{
	res.redirect("http://example.org/some_other_url");
}

void test()
{
	auto router = new URLRouter;
	router.get("/old_url", &request_handler);
	HTTPServerSettings settings;
	listenHTTP!router(settings);
}

Meta