diff --git a/config.go b/config.go index 3e07003..9f2464f 100644 --- a/config.go +++ b/config.go @@ -144,6 +144,7 @@ type configMicropubMedia struct { type configRegexRedirect struct { From string `mapstructure:"from"` To string `mapstructure:"to"` + Type int `mapstructure:"type"` } type configActivityPub struct { diff --git a/regexRedirects.go b/regexRedirects.go index 21a484b..cbf01bc 100644 --- a/regexRedirects.go +++ b/regexRedirects.go @@ -10,6 +10,7 @@ var regexRedirects []*regexRedirect type regexRedirect struct { From *regexp.Regexp To string + Type int } func initRegexRedirects() error { @@ -21,6 +22,7 @@ func initRegexRedirects() error { regexRedirects = append(regexRedirects, ®exRedirect{ From: re, To: cr.To, + Type: cr.Type, }) } return nil @@ -33,7 +35,11 @@ func checkRegexRedirects(next http.Handler) http.Handler { newPath := re.From.ReplaceAllString(oldPath, re.To) if oldPath != newPath { r.URL.Path = newPath - http.Redirect(w, r, r.URL.String(), http.StatusFound) + code := re.Type + if code == 0 { + code = http.StatusFound + } + http.Redirect(w, r, r.URL.String(), code) return } }