router: redirect repo.html and /repo/ to canonical repo
This commit is contained in:
parent
7cc7c7dc93
commit
124882da9a
16
main.go
16
main.go
@ -285,6 +285,22 @@ func (this *Application) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
this.Bannerpage(w, r, parts[1])
|
this.Bannerpage(w, r, parts[1])
|
||||||
|
|
||||||
} else if parts := this.rxRepoPage.FindStringSubmatch(r.URL.Path); parts != nil {
|
} 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])
|
this.Repopage(w, r, parts[1])
|
||||||
|
|
||||||
} else if r.URL.Path == `/static/logo.png` {
|
} else if r.URL.Path == `/static/logo.png` {
|
||||||
|
Loading…
Reference in New Issue
Block a user