Skip to content

Redirect subdomain to main domain #1759

Answered by aldas
maciej-jezierski asked this question in Q&A
Discussion options

You must be logged in to vote

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)
		}
	})

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@maciej-jezierski
Comment options

@maciej-jezierski
Comment options

Answer selected by maciej-jezierski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants