Redirects

Issuing a HTTP redirect is easy. Both internal and external locations are supported.

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

Issuing a Router redirect, use HandleContext like below.

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