From 124882da9af4dc079d0ff921aec026d064d79308 Mon Sep 17 00:00:00 2001 From: mappu Date: Mon, 4 May 2020 17:18:57 +1200 Subject: [PATCH] router: redirect repo.html and /repo/ to canonical `repo` --- main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/main.go b/main.go index 4e5b794..8d4f08a 100644 --- a/main.go +++ b/main.go @@ -285,6 +285,22 @@ func (this *Application) ServeHTTP(w http.ResponseWriter, r *http.Request) { this.Bannerpage(w, r, parts[1]) } else if parts := this.rxRepoPage.FindStringSubmatch(r.URL.Path); parts != nil { + + // Support /repo.html URIs for backward compatibility + if strings.HasSuffix(parts[1], `.html`) { + w.Header().Set(`Location`, r.URL.Path[0:len(r.URL.Path)-5]) + w.WriteHeader(301) + return + } + + // The regexp supports an optional trailing slash + // Redirect to canonical no-trailing-slash + if strings.HasSuffix(r.URL.Path, `/`) { + w.Header().Set(`Location`, `/`+parts[1]) // n.b. parts[1] isn't urldecoded yet + w.WriteHeader(301) + return + } + this.Repopage(w, r, parts[1]) } else if r.URL.Path == `/static/logo.png` {