0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2025-01-13 22:51:08 -05:00
caddy/middleware/redirect.go

24 lines
480 B
Go
Raw Normal View History

2015-01-13 14:43:45 -05:00
package middleware
import (
"net/http"
"github.com/mholt/caddy/config"
)
// Redirect is middleware for redirecting certain requests
// to other locations.
func Redirect(redirs []config.Redirect) Middleware {
return func(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
for _, rule := range redirs {
if r.URL.Path == rule.From {
http.Redirect(w, r, rule.To, rule.Code)
break
}
}
next(w, r)
}
}
}