0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00
caddy/middleware/redirect.go
2015-01-13 12:43:45 -07:00

23 lines
480 B
Go

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