Redirecting https://www.domain.com to https://domain.com in Go -


right doing redirect of http:// https:// this:

func main() {     router := httprouter.new()     router.post("/api/register", tohandle(register))     router.get("/api/token/verify/:token", tohandle(verifytoken))     router.get("/api/availability/username/:username", tohandle(usernameavailability))     router.post("/api/search/cities", tohandle(searchcities))     router.post("/api/user", tohandle(createuser))     router.get("/api/user/:id", tohandle(userbyid))     router.post("/api/login", tohandle(login))     router.notfound = &servestatic{}      certificate := "/srv/ssl/ssl-bundle.crt"     privatekey := "/srv/ssl/private.key"      go func() {         if err := http.listenandserve(":80", http.handlerfunc(redirecttls)); err != nil {             log.fatalf("listenandserve error: %v", err)         }     }()     log.fatal(http.listenandservetls(":443", certificate, privatekey, router))   }  func redirecttls(w http.responsewriter, r *http.request) {     http.redirect(w, r, "https://domain.com"+r.requesturi, http.statusmovedpermanently) }  type servestatic struct{}  func (df *servestatic) servehttp(w http.responsewriter, req *http.request) {      path := filepath.fromslash(config.dirroot + req.url.path)     data, err := ioutil.readfile(path)      var contenttype string      if err == nil {          if strings.hassuffix(path, ".css") {             contenttype = "text/css"         } else if strings.hassuffix(path, ".html") {             contenttype = "text/html"         } else if strings.hassuffix(path, ".js") {             contenttype = "application/javascript"         } else if strings.hassuffix(path, ".png") {             contenttype = "image/png"         } else if strings.hassuffix(path, ".jpg") {             contenttype = "image/jpeg"         } else if strings.hassuffix(path, ".ico") {             contenttype = "image/x-icon"         } else {             contenttype = "text/plain"         }          // spew.dump(path)          w.header().add("content-type", contenttype)          // prefix files gz such "all.gz.js" if want gzipped files served.         if strings.contains(path, ".gz.") {             w.header().add("content-encoding", "gzip")         }          w.write(data)      } else {          path := filepath.fromslash(config.dirroot + "/index.html")         data, err = ioutil.readfile(path)         contenttype = "text/html"          if err == nil {             w.header().add("content-type", contenttype)             w.write(data)         } else {             w.writeheader(404)             w.write([]byte("404 - " + http.statustext(404)))         }      } } 

but not redirect https://www.domain.com https://domain.com, redirects http://domain.com https://domain.com.

how can detect requests start https://www.domain.com?

any suggestions on how can achieved?


Comments