Skip to content

How can I redirect to a different Host? #2795

Answered by robjtede
OZoneGuy asked this question in Q&A
Discussion options

You must be logged in to vote

There are redirect responders in actix-web-lab: https://docs.rs/actix-web-lab/0.16/actix_web_lab/web/struct.Redirect.html#method.to

async fn handler() -> impl Responder {
  Redirect::to("https://duck.com")
}

The Redirect struct will be promoted to Actix Web in an upcoming 4.x release.

You can also construct redirect responses yourself using 30x status codes and a Location header.

Replies: 2 comments 4 replies

Comment options

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

Answer selected by robjtede
Comment options

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

@KaiyuanMa
Comment options

@robjtede
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
4 participants