package main import ( "fmt" "net/http" "strings" ) func greet(w http.ResponseWriter, r *http.Request) { // Check if the Host header ends with "mzsl.nl" if !strings.HasSuffix(r.Host, "mzsl.nl") { w.WriteHeader(http.StatusNotFound) w.Write([]byte("404, url not found")) fmt.Printf("Host: %s not found\n", r.Host) return } // Replace "localhost" with "mziesel.nl" in the Host header newHost := strings.Replace(r.Host, "localhost", "mziesel.nl", 1) // Construct the new URL for redirection newUrl := "https://" + newHost + r.URL.String() fmt.Println(newUrl) // Set the Location header and respond with a 301 Moved Permanently status w.Header().Set("Location", newUrl) w.WriteHeader(http.StatusMovedPermanently) w.Write([]byte("url found, redirecting...")) } func main() { http.HandleFunc("/", greet) http.ListenAndServe(":8080", nil) }