Skip to content

How to make an redirect? #511

Discussion options

You must be logged in to vote

If you have a fully qualified URL, you can use Response.redirect.

export function handler(req: Request): Response {
  return Response.redirect("https://example.com", 307);
}

If you want to redirect to a relative path on the current domain:

export function handler(req: Request): Response {
  return new Response("", {
    status: 307,
    headers: { Location: "/my/new/relative/path" },
  });
}

Replies: 6 comments 8 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@ruzmetovJob
Comment options

@TranquilMarmot
Comment options

@marvinhagemeister
Comment options

Answer selected by lucacasonato
Comment options

You must be logged in to vote
2 replies
@vixalien
Comment options

@leesei
Comment options

Comment options

You must be logged in to vote
1 reply
@sylc
Comment options

Comment options

You must be logged in to vote
1 reply
@marvinhagemeister
Comment options

Comment options

You must be logged in to vote
1 reply
@PhoneDroid
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
Converted from issue

This discussion was converted from issue #507 on July 15, 2022 14:45.