Redirect subdomain to main domain #1759
Answered
by
aldas
maciej-jezierski
asked this question in
Q&A
-
Hi all, is it possible to redirect permanently subdomains to the main domain? |
Beta Was this translation helpful? Give feedback.
Answered by
aldas
Jan 18, 2021
Replies: 1 comment 2 replies
-
You could create something similar to redirect middleware e.Use(func(next HandlerFunc) HandlerFunc {
return func(c Context) error {
if strings.HasSuffix(c.Request().Host, ".mydomain.com") { // does not work with "www.mydomain.com:8080". but you get the idea
return c.Redirect(http.StatusMovedPermanently, "https://mydomain.com")
}
return next(c)
}
}) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
maciej-jezierski
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could create something similar to redirect middleware