diff options
author | thinkpadmaster <a.scerba02@gmail.com> | 2023-07-21 22:52:14 -0500 |
---|---|---|
committer | Alex Scerba <alex@scerba.org> | 2024-10-29 13:19:57 -0400 |
commit | 5c088b1fd9c82aff92b64d76fc6a11753b356447 (patch) | |
tree | bd2f4a853717ace2626fe164f5ee7046f9913a99 /main.go | |
parent | ab653f7555495d674104d1d41ba4a79bc55fd104 (diff) |
Redirect alexscerba.com to www.alexscerba.com
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -4,6 +4,7 @@ import ( "log" "net/http" "os" + "strings" ) type application struct { @@ -23,6 +24,17 @@ func (app *application) httpsRedirect(w http.ResponseWriter, req *http.Request) http.StatusMovedPermanently) } +func (app *application) wwwRedirect(h http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if !strings.HasPrefix(r.Host, "www.") { + http.Redirect(w, r, r.URL.Scheme+"://www."+r.Host+r.RequestURI, 302) + return + } + + h.ServeHTTP(w, r) + }) +} + func main() { infoLog := log.New(os.Stdout, "INFO\t", log.Ldate|log.Ltime) errorLog := log.New(os.Stderr, "ERROR\t", log.Ldate|log.Ltime|log.Lshortfile) |