github.com/gofiber/fiber/v2@v2.47.0/docs/api/middleware/rewrite.md (about) 1 --- 2 id: rewrite 3 title: Rewrite 4 --- 5 6 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. 7 8 9 ## Signatures 10 11 ```go 12 func New(config ...Config) fiber.Handler 13 ``` 14 15 ### Examples 16 ```go 17 package main 18 19 import ( 20 "github.com/gofiber/fiber/v2" 21 "github.com/gofiber/fiber/v2/middleware/rewrite" 22 ) 23 24 func main() { 25 app := fiber.New() 26 27 app.Use(rewrite.New(rewrite.Config{ 28 Rules: map[string]string{ 29 "/old": "/new", 30 "/old/*": "/new/$1", 31 }, 32 })) 33 34 app.Get("/new", func(c *fiber.Ctx) error { 35 return c.SendString("Hello, World!") 36 }) 37 app.Get("/new/*", func(c *fiber.Ctx) error { 38 return c.SendString("Wildcard: " + c.Params("*")) 39 }) 40 41 app.Listen(":3000") 42 } 43 44 ``` 45 46 **Test:** 47 48 ```curl 49 curl http://localhost:3000/old 50 curl http://localhost:3000/old/hello 51 ```