Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repository redirect not use modified ROOT_URL #8588

Closed
2 of 7 tasks
tomac4t opened this issue Oct 19, 2019 · 3 comments · Fixed by #8632
Closed
2 of 7 tasks

Repository redirect not use modified ROOT_URL #8588

tomac4t opened this issue Oct 19, 2019 · 3 comments · Fixed by #8632
Labels

Comments

@tomac4t
Copy link

tomac4t commented Oct 19, 2019

Description

I install Gitea under a sub-path /git/ with Nginx as a reverse proxy.

When I modified "repository name", the old repo link should be redirected to the new link. I am expected it redirect to /git/<OwnerNAME>/<RepoName>/, but it actually redirect to /<OwnerNAME>/<RepoName>/.

app.ini:

[server]
PROTOCOL         = http
SSH_DOMAIN       = localhost
DOMAIN           = localhost
HTTP_ADDR        = 127.0.0.1
HTTP_PORT        = 8000
ROOT_URL         = https://example.com/git/
DISABLE_SSH      = true
LFS_START_SERVER = true
LFS_CONTENT_PATH = /var/lib/gitea/data/lfs
[...]

nginx.conf:

location ^~/git/ {
    proxy_pass http://localhost:8000/;
}
[...]

Screenshots

@zeripath
Copy link
Contributor

zeripath commented Oct 20, 2019

So redirects are managed by this code:

// RedirectToRepo redirect to a differently-named repository
func RedirectToRepo(ctx *Context, redirectRepoID int64) {
ownerName := ctx.Params(":username")
previousRepoName := ctx.Params(":reponame")
repo, err := models.GetRepositoryByID(redirectRepoID)
if err != nil {
ctx.ServerError("GetRepositoryByID", err)
return
}
redirectPath := strings.Replace(
ctx.Req.URL.Path,
fmt.Sprintf("%s/%s", ownerName, previousRepoName),
fmt.Sprintf("%s/%s", repo.MustOwnerName(), repo.Name),
1,
)
if ctx.Req.URL.RawQuery != "" {
redirectPath += "?" + ctx.Req.URL.RawQuery
}
ctx.Redirect(redirectPath)
}

Which basically does a straight replacement of the path that it is given.

Adding the setting.AppSubUrl to the path at

ctx.Redirect(redirectPath)

should be enough to make this work but it could do with some checking

@6543
Copy link
Member

6543 commented Oct 21, 2019

@zeripath is there a PR you are working on right now?

@zeripath
Copy link
Contributor

Nope I just read the comment and realised how to fix it before bed. I won't really get a chance to look at this until evening UK time today so if you or anyone else fancies it in the meantime - please do send the PR.

@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants