Answer the question
In order to leave comments, you need to log in
How to redirect all requests to a domain to another domain without a specific uri?
http.GET("/", func(c *gin.Context) {
c.Redirect(302, "https://wifer-test.ru")
})
Answer the question
In order to leave comments, you need to log in
To do this, it is better to make middleware and do everything you need already there
. either transfer control further, or redirect and complete the processing of the request.
https://github.com/gin-gonic/gin#custom-middleware
Something like this
func DomainRedirect() gin.HandlerFunc {
return func(c *gin.Context) {
if ваше_условие {
c.Redirect(302, "https://wifer-test.ru/" + c.Request.URL.String())
return
}
c.Next()
}
}
....
r := gin.New()
r.Use(DomainRedirect())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question