caddyserver/caddy · error

mapping %d has both input and input_regexp fields specified,

Error message

mapping %d has both input and input_regexp fields specified, which is confusing

What it means

Validate in the map handler rejects any mapping that sets both `input` (exact string) and `input_regexp`, because the two are mutually exclusive matching strategies and keeping both is ambiguous. The mapping index is reported.

Source

Thrown at modules/caddyhttp/map/map.go:101

	// TODO: improve efficiency even further by using an actual map type
	// for the non-regexp mappings, OR sort them and do a binary search

	return nil
}

// Validate ensures that h is configured properly.
func (h *Handler) Validate() error {
	nDest, nDef := len(h.Destinations), len(h.Defaults)
	if nDef > 0 && nDef != nDest {
		return fmt.Errorf("%d destinations != %d defaults", nDest, nDef)
	}

	seen := make(map[string]int)
	for i, m := range h.Mappings {
		// prevent confusing/ambiguous mappings
		if m.Input != "" && m.InputRegexp != "" {
			return fmt.Errorf("mapping %d has both input and input_regexp fields specified, which is confusing", i)
		}

		// prevent duplicate mappings
		input := m.Input
		if m.InputRegexp != "" {
			input = m.InputRegexp
		}
		if prev, ok := seen[input]; ok {
			return fmt.Errorf("mapping %d has a duplicate input '%s' previously used with mapping %d", i, input, prev)
		}
		seen[input] = i

		// ensure mappings have 1:1 output-to-destination correspondence
		nOut := len(m.Outputs)
		if nOut != nDest {
			return fmt.Errorf("mapping %d has %d outputs but there are %d destinations defined", i, nOut, nDest)
		}
	}

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Delete one of the two fields — keep `input` for exact matches or `input_regexp` for patterns.
  2. Split into two mappings if you need both behaviors.

Example fix

// before (JSON)
{"input":"foo","input_regexp":"^foo$","outputs":["bar"]}

// after (JSON)
{"input_regexp":"^foo$","outputs":["bar"]}
Defensive patterns

Strategy: validation

Validate before calling

func exclusiveInput(m Mapping) bool {
	return !(m.Input != "" && m.InputRegexp != "")
}

Prevention

When it happens

Trigger: JSON map mapping objects containing {"input":"foo","input_regexp":"^foo","outputs":[...]}; Caddyfile regex mappings that also set an inline input.

Common situations: Editing a JSON config by hand and leaving the old field when switching to regexp; tooling that emits both fields defensively.

Related errors


AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15). Data as JSON: /api/errors/be4fc48f63483d72. Report an issue: GitHub.