mirror of
https://github.com/kataras/iris.git
synced 2026-01-09 21:15:56 +00:00
Finish the feature request https://github.com/kataras/iris/issues/235#issuecomment-229383650
This commit is contained in:
12
http.go
12
http.go
@@ -403,6 +403,18 @@ func (s *Server) Open() error {
|
||||
s.Config.ListeningAddr = config.DefaultServerHostname + a
|
||||
}
|
||||
|
||||
if s.Config.RedirectTo != "" {
|
||||
// override the handler and redirect all requests to this addr
|
||||
s.Handler = func(reqCtx *fasthttp.RequestCtx) {
|
||||
path := string(reqCtx.Path())
|
||||
redirectTo := s.Config.RedirectTo
|
||||
if path != "/" {
|
||||
redirectTo += "/" + path
|
||||
}
|
||||
reqCtx.Redirect(redirectTo, StatusMovedPermanently)
|
||||
}
|
||||
}
|
||||
|
||||
if s.Config.Mode > 0 {
|
||||
return s.listenUNIX()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user