redirects

package
v1.51.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package redirects provides functions for parsing and rewriting URLs according to Netlify style _redirects syntax

Index

Constants

View Source
const (
	// ConfigFile is the default name of the file containing the redirect rules.
	// It follows Netlify's syntax but we don't support all of the special options yet
	//  - https://docs.netlify.com/routing/redirects/
	//  - https://docs.netlify.com/routing/redirects/redirect-options/
	ConfigFile = "_redirects"
)

Variables

View Source
var (
	// ErrNoRedirect is the error thrown when a no redirect rule matches while trying to Rewrite URL.
	// This means that no redirect applies to the URL and you can fallback to serving actual content instead.
	ErrNoRedirect = errors.New("no redirect found")
)

Functions

This section is empty.

Types

type Redirects

type Redirects struct {
	// contains filtered or unexported fields
}

func ParseRedirects

func ParseRedirects(ctx context.Context, root vfs.Root) *Redirects

ParseRedirects decodes Netlify style redirects from the projects `.../public/_redirects` https://docs.netlify.com/routing/redirects/#syntax-for-the-redirects-file

func (*Redirects) Rewrite

func (r *Redirects) Rewrite(originalURL *url.URL) (*url.URL, int, error)

Rewrite takes in a URL and uses the parsed Netlify rules to rewrite the URL to the new location if it matches any rule

func (*Redirects) Status

func (r *Redirects) Status() string

Status maps over each redirect rule and returns any error message

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL