Documentation ¶
Overview ¶
Package redirects provides Netlify style _redirects file format parsing.
Example ¶
h := Must(ParseString(` # Implicit 301 redirects /home / /blog/my-post.php /blog/my-post /news /blog /google https://www.google.com # Redirect with a 301 /home / 301 # Redirect with a 302 /my-redirect / 302 # Rewrite a path /pass-through /index.html 200 # Show a custom 404 for this path /ecommerce /store-closed 404 # Single page app rewrite /* /index.html 200 # Proxying /api/* https://api.example.com/:splat 200 `)) enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") enc.Encode(h)
Output: [ { "From": "/home", "To": "/", "Status": 301 }, { "From": "/blog/my-post.php", "To": "/blog/my-post", "Status": 301 }, { "From": "/news", "To": "/blog", "Status": 301 }, { "From": "/google", "To": "https://www.google.com", "Status": 301 }, { "From": "/home", "To": "/", "Status": 301 }, { "From": "/my-redirect", "To": "/", "Status": 302 }, { "From": "/pass-through", "To": "/index.html", "Status": 200 }, { "From": "/ecommerce", "To": "/store-closed", "Status": 404 }, { "From": "/*", "To": "/index.html", "Status": 200 }, { "From": "/api/*", "To": "https://api.example.com/:splat", "Status": 200 } ]
Index ¶
Examples ¶
Constants ¶
View Source
const MaxFileSizeInBytes = 65536
64 KiB
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Rule ¶
type Rule struct { // From is the path which is matched to perform the rule. From string // To is the destination which may be relative, or absolute // in order to proxy the request to another URL. To string // Status is one of the following: // // - 3xx a redirect // - 200 a rewrite // - defaults to 301 redirect // Status int }
A Rule represents a single redirection or rewrite rule.
func (*Rule) MatchAndExpandPlaceholders ¶
MatchAndExpandPlaceholders expands placeholders in `r.To` and returns true if the provided path matches. Otherwise it returns false.
Click to show internal directories.
Click to hide internal directories.