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

RedirectTrailingSlash not working if there are more than one child route #2211

Closed
ashishraman opened this issue Jan 16, 2020 · 1 comment · Fixed by #3227
Closed

RedirectTrailingSlash not working if there are more than one child route #2211

ashishraman opened this issue Jan 16, 2020 · 1 comment · Fixed by #3227
Labels

Comments

@ashishraman
Copy link

ashishraman commented Jan 16, 2020

Description

RedirectTrailingSlash not working if there are more than two child route.

How to reproduce

package main

import (
	"github.com/gin-gonic/gin"
)

func main() {
	g := gin.New()
        router := g.Group("/v1")
	router.GET("/hello", dummyFunction)
        router.GET("/hello/a", dummyFunction)
        router.GET("/hello/b", dummyFunction)
	g.Run(":9000")
}

Expectations

$ curl http://localhost:8201/hello/ should redirect [301] to {{URL}}/hello 

Actual result

Getting 404

The same works if there is only one child /hello/a

Environment

  • go version: go version go1.13.3 linux/amd64
  • gin version (or commit ref): v1.5.0
  • operating system: ubuntu 16.04
@densone
Copy link

densone commented Jan 18, 2020

Here's what I think is happening.

/hello/ is returning a 404 because the router knows there are routes that live under /hello/

I guessing the fix would be:

if there are routes under /hello/ and you have a trailing slash, and theres nothing after the trailing slash, redirect.

@thinkerou thinkerou added the bug label Jul 3, 2022
appleboy pushed a commit that referenced this issue Nov 6, 2022
thxCode pushed a commit to seal-io/gin that referenced this issue Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants