traefik redirect middleware snippet

palette/k3sYt2 go expires in 6d
raw copy download delete
main.go · 18 lines · 412 bytes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
package main import ( "net/http" ) // redirect http to https with noop middleware func httpsRedirect() http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.TLS == nil { target := "https://" + r.Host + r.URL.RequestURI() http.Redirect(w, r, target, http.StatusMovedPermanently) return } w.WriteHeader(http.StatusOK) }) }
Created 2m ago 12 views never expires public