mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-24 22:06:57 +00:00
Ignore repo and branch in URL
This commit is contained in:
parent
a3f60cea18
commit
fa769b728e
2 changed files with 4 additions and 1 deletions
|
@ -14,7 +14,7 @@ from to [status]
|
||||||
```
|
```
|
||||||
|
|
||||||
* Lines starting with `#` are ignored
|
* 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
|
* `to` - the path or URL to redirect to
|
||||||
* `status` - status code to use when redirecting (default 301)
|
* `status` - status code to use when redirecting (default 301)
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,9 @@ func (o *Options) matchRedirects(ctx *context.Context, giteaClient *gitea.Client
|
||||||
if len(redirects) > 0 {
|
if len(redirects) > 0 {
|
||||||
for _, redirect := range redirects {
|
for _, redirect := range redirects {
|
||||||
reqUrl := ctx.Req.RequestURI
|
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
|
// check if from url matches request url
|
||||||
if strings.TrimSuffix(redirect.From, "/") == strings.TrimSuffix(reqUrl, "/") {
|
if strings.TrimSuffix(redirect.From, "/") == strings.TrimSuffix(reqUrl, "/") {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue