about summary refs log tree commit diff stats
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/server/server.go13
1 files changed, 4 insertions, 9 deletions
diff --git a/internal/server/server.go b/internal/server/server.go
index 6ef715b..0bbfba4 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -188,7 +188,7 @@ func New(runtimeConfig *Config, log *log.Logger) (*Server, error) {
 		re := regexp.MustCompile(
 			"^(.*)\\." + strings.ReplaceAll(config.WildcardDomain, ".", `\.`) + "$",
 		)
-		replace := "${0}." + config.Domains[0]
+		replace := "${1}." + config.Domains[0]
 		loggingMux.Handle(config.BaseURL.Hostname()+"/", mux)
 		loggingMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
 			if slices.Contains(config.Domains, r.Host) {
@@ -196,14 +196,9 @@ func New(runtimeConfig *Config, log *log.Logger) (*Server, error) {
 				newURL := config.BaseURL.JoinPath(path)
 				http.Redirect(w, r, newURL.String(), http.StatusMovedPermanently)
 			} else {
-				matches := re.FindSubmatchIndex([]byte(r.Host))
-				if matches == nil {
-					http.Redirect(w, r, config.BaseURL.String(), http.StatusTemporaryRedirect)
-
-					return
-				}
-				newHost := re.ExpandString([]byte{}, replace, r.Host, matches)
-				http.Redirect(w, r, string(newHost), http.StatusTemporaryRedirect)
+				url := config.BaseURL
+				url.Host = re.ReplaceAllString(r.Host, replace)
+				http.Redirect(w, r, url.String(), http.StatusTemporaryRedirect)
 			}
 		})
 	} else {