mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
23 lines
480 B
Go
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)
|
|
}
|
|
}
|
|
}
|