Redirect from Context
The Redirect method sends a redirect response to the client of an absolute or relative target URL. It accepts 2 input arguments, a string and an optional integer. The first parameter is the target url to redirect. The second one is the HTTP status code should be sent among redirection response, If the second parameter is missing, then it defaults to 302 (StatusFound). It can be set to 301 (Permant redirect), StatusTemporaryRedirect(307) or 303 (StatusSeeOther) if POST method.
1
Redirect(urlToRedirect string, statusHeader ...int)
Copied!
Usage
Redirect from /home to /.
1
package main
2
3
import "github.com/kataras/iris/v12"
4
5
func main() {
6
app := iris.New()
7
8
app.Get("/", index)
9
app.Get("/home", home)
10
11
app.Listen(":8080")
12
}
13
14
func index(ctx iris.Context) {
15
ctx.Writef("Hello, %s!", "World")
16
}
17
18
func home(ctx iris.Context) {
19
ctx.Redirect("/", iris.StatusPermanentRedirect)
20
}
Copied!
Last modified 1mo ago
Export as PDF
Copy link