mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-13 22:51:08 -05:00
24 lines
480 B
Go
24 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)
|
||
|
}
|
||
|
}
|
||
|
}
|