Redirect to the given url with status code defaulting to
Status#FOUND.
rsp.redirect("/foo/bar");
rsp.redirect("http://example.com");
rsp.redirect("http://example.com");
rsp.redirect("../login");
Redirects can be a fully qualified URI for redirecting to a different site:
rsp.redirect("http://google.com");
Redirects can be relative to the root of the host name. For example, if you were
on
http://example.com/admin/post/new
, the following redirect to /admin would
land you at
http://example.com/admin
:
rsp.redirect("/admin");
Redirects can be relative to the current URL. A redirection of post/new, from
http://example.com/blog/admin/
(notice the trailing slash), would give you
http://example.com/blog/admin/post/new.
rsp.redirect("post/new");
Redirecting to post/new from
http://example.com/blog/admin
(no trailing slash),
will take you to
http://example.com/blog/post/new
.
If you found the above behavior confusing, think of path segments as directories (have trailing
slashes) and files, it will start to make sense.
Pathname relative redirects are also possible. If you were on
http://example.com/admin/post/new
, the following redirect would land you at
http//example.com/admin
:
rsp.redirect("..");
A back redirection will redirect the request back to the
Referer
, defaulting to
/
when missing.
rsp.redirect("back");