Redirect
Fiber용 리다이렉션 미들웨어.
Signatures
func New(config ...Config) fiber.Handler
Examples
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/redirect"
)
func main() {
app := fiber.New()
app.Use(redirect.New(redirect.Config{
Rules: map[string]string{
"/old": "/new",
"/old/*": "/new/$1",
},
StatusCode: 301,
}))
app.Get("/new", func(c *fiber.Ctx) error {
return c.SendString("Hello, World!")
})
app.Get("/new/*", func(c *fiber.Ctx) error {
return c.SendString("Wildcard: " + c.Params("*"))
})
app.Listen(":3000")
}
테스트:
curl http://localhost:3000/old
curl http://localhost:3000/old/hello
Config
속성
타입
설명
기본값
Next
func(*fiber.Ctx) bool
미들웨어를 건너뛸 함수를 정의합니다.
nil
Rules
map[string]string
URL 경로 재작성 규칙을 정의합니다. 별표로 캡처된 값은 $1, $2 등의 인덱스로 검색할 수 있습니다.
필수
StatusCode
int
리다이렉션 시 상태 코드입니다. Redirect가 비활성화된 경우 무시됩니다.
302 임시 리다이렉션
Default Config
var ConfigDefault = Config{
StatusCode: fiber.StatusFound,
}
Last updated