Redirect middleware for Fiber provides powerful URL redirection with pattern matching and variable capture. It allows you to define URL rewrite rules that redirect requests to new paths.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/gofiber/fiber/llms.txt
Use this file to discover all available pages before exploring further.
Signatures
Usage
Basic Usage
Pattern Matching with Wildcards
Custom Status Code
Skip Specific Paths
Configuration
Defines a function to skip this middleware when it returns true.
Defines the URL path redirect rules. The values captured in asterisk wildcards can be retrieved by index e.g.
$1, $2 and so on.Example rules:"/old": "/new"- Simple redirect"/api/*": "/$1"- Capture and reuse path"/js/*": "/public/javascript/$1"- Add prefix"/users/*/orders/*": "/user/$1/order/$2"- Multiple captures
The HTTP status code to use when redirecting. Common values:
301- Permanent redirect302- Temporary redirect (default)307- Temporary redirect (preserves request method)308- Permanent redirect (preserves request method)
Default Config
Common Use Cases
Legacy URL Migration
API Versioning
URL Normalization
Language Path Redirects
Marketing Campaign URLs
Best Practices
Use Permanent Redirects for SEO
Order Matters
Combine with Conditional Logic
Notes
- Wildcards (
*) in rules capture path segments that can be referenced as$1,$2, etc. - Rules are processed as written in the map
- The middleware uses regular expressions internally for pattern matching
- Redirect preserves query parameters from the original request