redirs

package module
v0.0.0-...-b005712 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2025 License: MIT Imports: 9 Imported by: 0

README

redirs

Go Reference Go Report Card

Usage

example.com {

    redir_random /redir/* {
		to https://example.com{uri} https://example.hu{uri}
		to https://example.eu{uri}
		code temporary
	}

    ...
}

Build

xcaddy build --with git.gorbe.io/caddy/redirs

Or just copy the build argument

--with git.gorbe.io/caddy/redirs

Go module

go get git.gorbe.io/caddy/redirs@latest

Get the latest commit (if Go module proxy is not updated):

go get "git.gorbe.io/caddy/redirs@$(curl -s 'https://git.gorbe.io/api/v1/repos/caddy/redirs/commits' | jq -r '.[0].sha')"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Random

type Random struct {
	// List of target locations to randomly redirect to.
	// Placeholders are supported.
	To []string `json:"to,omitempty"`

	// HTTP status code for redirect.
	// Can be:
	//  - `301` or `"permanent"`
	//  - `308`
	//  - `302` or `"temporary"`
	//  - `303`
	//  - `307`
	//
	// Default to `302`.
	Code int `json:"code,omitempty"`
	// contains filtered or unexported fields
}

Random redirects to a randomly selected Location from list with code.

Caddyfile syntax:

redir_random [<matcher>] {
	to <to> <to>
	code <code>
}

This module supports placeholders in the `to` list. The `redir_random` directive comes after the `redir` in the [directive order](https://caddyserver.com/docs/caddyfile/directives#directive-order).

IMPORTANT

This module uses math/rand so might be easily predictable.

func (Random) CaddyModule

func (Random) CaddyModule() caddy.ModuleInfo

CaddyModule implements the github.com/caddyserver/caddy/v2.Module interface.

func (*Random) Provision

func (r *Random) Provision(ctx caddy.Context) error

Provision implements the github.com/caddyserver/caddy/v2.Provisioner interface. Sets Code to the default "302" if not set.

func (*Random) UnmarshalCaddyfile

func (r *Random) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile implements caddyfile.Unmarshaler. Syntax:

redir_random [<matcher>] {
  to <to> <to>
  code [<code>]
}

func (*Random) Validate

func (r *Random) Validate() error

Validate implements the github.com/caddyserver/caddy/v2.Validator interface.

Jump to

Keyboard shortcuts

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