mirror of
https://github.com/gofiber/fiber.git
synced 2025-05-11 02:01:38 +00:00
* ♻️ refactor: merge adaptor, helmet, keyauth, redirect, rewrite middlewares to core
* fix linting issues
* fix linting issues
* fix linting issues
* update
891 B
891 B
id, title
id | title |
---|---|
rewrite | Rewrite |
Rewrite middleware rewrites the URL path based on provided rules. It can be helpful for backward compatibility or just creating cleaner and more descriptive links.
Signatures
func New(config ...Config) fiber.Handler
Examples
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/rewrite"
)
func main() {
app := fiber.New()
app.Use(rewrite.New(rewrite.Config{
Rules: map[string]string{
"/old": "/new",
"/old/*": "/new/$1",
},
}))
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")
}
Test:
curl http://localhost:3000/old
curl http://localhost:3000/old/hello