all repos — website @ 8f536a3b6a915cfb2f2fff909d52ba7354b6315a

My website

server: 404 if host not recognised
Alan Pearce alan@alanpearce.eu
Wed, 04 Dec 2024 19:59:33 +0100
commit

8f536a3b6a915cfb2f2fff909d52ba7354b6315a

parent

60dbf7194e15c8ffafb530769611396ac361640e

1 files changed, 3 insertions(+), 1 deletions(-)

jump to
M internal/server/server.gointernal/server/server.go
@@ -194,10 +194,12 @@ if slices.Contains(config.Domains, r.Host) { 				path, _ := website.CanonicalisePath(r.URL.Path)
 				newURL := config.BaseURL.JoinPath(path)
 				http.Redirect(w, r, newURL.String(), http.StatusMovedPermanently)
-			} else {
+			} else if re.MatchString(r.Host) {
 				url := config.BaseURL
 				url.Host = re.ReplaceAllString(r.Host, replace)
 				http.Redirect(w, r, url.String(), http.StatusTemporaryRedirect)
+			} else {
+				http.NotFound(w, r)
 			}
 		})
 	} else {