diff --git a/FEATURES.md b/FEATURES.md index 2a07799..7560a1d 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -14,7 +14,7 @@ from to [status] ``` * Lines starting with `#` are ignored -* `from` - the path to redirect from +* `from` - the path to redirect from (Note: repository and branch names are removed from request URLs) * `to` - the path or URL to redirect to * `status` - status code to use when redirecting (default 301) diff --git a/server/upstream/redirects.go b/server/upstream/redirects.go index f53917a..b0e164d 100644 --- a/server/upstream/redirects.go +++ b/server/upstream/redirects.go @@ -67,6 +67,9 @@ func (o *Options) matchRedirects(ctx *context.Context, giteaClient *gitea.Client if len(redirects) > 0 { for _, redirect := range redirects { reqUrl := ctx.Req.RequestURI + // remove repo and branch from request url + reqUrl = strings.TrimPrefix(reqUrl, "/" + o.TargetRepo) + reqUrl = strings.TrimPrefix(reqUrl, "/@" + o.TargetBranch) // check if from url matches request url if strings.TrimSuffix(redirect.From, "/") == strings.TrimSuffix(reqUrl, "/") {