Skip to content

Latest commit

 

History

History
35 lines (26 loc) · 808 Bytes

redirects.md

File metadata and controls

35 lines (26 loc) · 808 Bytes
title draft
リダイレクト
false

HTTP リダイレクトするのは簡単です。内部パス、外部URL両方のリダイレクトに対応しています。

r.GET("/test", func(c *gin.Context) {
	c.Redirect(http.StatusMovedPermanently, "http://www.google.com/")
})

Issuing a HTTP redirect from POST. Refer to issue: #444

r.POST("/test", func(c *gin.Context) {
	c.Redirect(http.StatusFound, "/foo")
})

Router でリダイレクトするには、下記のように HandleContext メソッドを使ってください。

r.GET("/test", func(c *gin.Context) {
    c.Request.URL.Path = "/test2"
    r.HandleContext(c)
})
r.GET("/test2", func(c *gin.Context) {
    c.JSON(200, gin.H{"hello": "world"})
})