You can change the URL of a request before any processing takes place this is sometimes useful for aliasing routes or when a route is move and it would be nice to still handle the old routes.
To rewrite a URL the server provides a Rewrite
function that uses regular
expression to match and transform the URL.
Configuration
This function expects a RewriteRules
map to be passed where the keys are regular
expressions patterns and the values are the finalized URLs. The final URLs can
also use the value of regular expression capture groups with the $1,$2,$3,
values.
rules := RewriteRules {
// /people/:id/profile -> /users/:id/profile
"/people/(.*)/profile": "/users/$1/profile",
}
Usage
svr := celerity.New()
svr.Pre(middelware.RewriteRules{
"/people/(.*)/profile": "/users/$1/profile",
})