Skip to content

Commit c53e1cb

Browse files
authored
Merge pull request #64 from renanbastos93/patch-1
doc: Redirects middleware.
2 parents be87096 + 9d25861 commit c53e1cb

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

middleware.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,3 +535,51 @@ func main() {
535535
}
536536
```
537537

538+
539+
## Redirect
540+
541+
Redirects middleware provides an HTTP redirect to the URL derived from the specified path, with specified status, a positive integer that corresponds to an HTTP status code.
542+
543+
**Installation**
544+
545+
```bash
546+
go get -u github.com/gofiber/redirect
547+
```
548+
549+
**Signature**
550+
551+
```go
552+
redirect.New(config ...Config) func(*Ctx)
553+
```
554+
555+
**Example**
556+
557+
```go
558+
package main
559+
560+
import (
561+
"github.com/gofiber/fiber"
562+
"github.com/gofiber/redirect"
563+
)
564+
565+
func main() {
566+
app := fiber.New()
567+
568+
app.Use(redirect.New(redirect.Config{
569+
Rules: map[string]string{
570+
"/old": "/new",
571+
"/old/*": "/new/$1",
572+
},
573+
Status: 301,
574+
}))
575+
576+
app.Get("/new", func(c *fiber.Ctx) {
577+
c.Send("Hello, World!")
578+
})
579+
app.Get("/new/*", func(c *fiber.Ctx) {
580+
c.Send("Wildcard: ", c.Params("*"))
581+
})
582+
583+
app.Listen(3000)
584+
}
585+
```

0 commit comments

Comments
 (0)