Skip to content

redir syntax and examples seem invalid in some cases #6517

@Jiehong

Description

@Jiehong

Looking at https://caddyserver.com/docs/caddyfile/directives/redir#syntax, it seems as if the matcher is optional according to the examples.

Yet, trying to use it without a matcher does not work (both caddy run and caddy validate complain).

This works:

...
handle_errors {
		@404 {
			expression `{err.status_code} == 404`
		}
		handle @404 {
			redir * /subdir/index.html
		}

		# Any other kind of error should be passed through
		handle {
			respond "Internal http server error: {err.trace}"
		}
	}

changing the redir line to redir /subdir/index.html leads to the following issue:

Error: adapting config using caddyfile: parsing caddyfile tokens for 'handle_errors': parsing caddyfile tokens for 'handle': parsing caddyfile tokens for 'redir': wrong argument count or unexpected line ending after 'redir', at Caddyfile:41, at Caddyfile:42, at Caddyfile:48

Yet, the doc shows 3 out of 4 examples without a matcher:

image

I guess the syntax doc should explain that a bit better, shouldn't it?

FYI:

  • caddy version: v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk=

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussion 💬The right solution needs to be found

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions