Add www redirect for main domain

This commit is contained in:
Moritz Marquardt 2021-12-02 00:00:00 +01:00
parent a48ba8ee49
commit 26dd1591f6
No known key found for this signature in database
GPG key ID: D5788327BEE388B6

View file

@ -180,6 +180,12 @@ func handler(ctx *fasthttp.RequestCtx) {
targetRepo = pathElements[0] targetRepo = pathElements[0]
targetPath = strings.Trim(strings.Join(pathElements[1:], "/"), "/") targetPath = strings.Trim(strings.Join(pathElements[1:], "/"), "/")
if targetOwner == "www" {
// www.codeberg.page redirects to codeberg.page
ctx.Redirect("https://" + string(MainDomainSuffix[1:]) + string(ctx.Path()), fasthttp.StatusPermanentRedirect)
return
}
// Check if the first directory is a repo with the second directory as a branch // Check if the first directory is a repo with the second directory as a branch
// example.codeberg.page/myrepo/@main/index.html // example.codeberg.page/myrepo/@main/index.html
if len(pathElements) > 1 && strings.HasPrefix(pathElements[1], "@") { if len(pathElements) > 1 && strings.HasPrefix(pathElements[1], "@") {