kataras/iris · error
redirect match: status code digits: %s [%d:%c]
Error message
redirect match: status code digits: %s [%d:%c]
What it means
parseRedirectMatchLine validates redirect rewrite rules of the form 'CODE PATTERN TARGET'. Every character of the status-code field must be a digit; when a non-digit is found at index i, the parser rejects the whole line with this error, naming the bad character and its position. This prevents a malformed code like '30x' from silently becoming code 30 or 0.
Source
Thrown at middleware/rewrite/rewrite.go:291
if match := r.pattern.ReplaceAllString(src, r.target); match != "" {
return match, true
}
}
return "", false
}
func parseRedirectMatchLine(s string) (*redirectMatch, error) {
parts := strings.Split(strings.TrimSpace(s), " ")
if len(parts) != 3 {
return nil, fmt.Errorf("redirect match: invalid line: %s", s)
}
codeStr, pattern, target := parts[0], parts[1], parts[2]
for i, ch := range codeStr {
if !isDigit(ch) {
return nil, fmt.Errorf("redirect match: status code digits: %s [%d:%c]", codeStr, i, ch)
}
}
code, err := strconv.Atoi(codeStr)
if err != nil {
// this should not happen, we check abt digit
// and correctly position the error too but handle it.
return nil, fmt.Errorf("redirect match: status code digits: %s: %v", codeStr, err)
}
regex := regexp.MustCompile(pattern)
if regex.MatchString(target) {
return nil, fmt.Errorf("redirect match: loop detected: pattern: %s vs target: %s", pattern, target)
}
v := &redirectMatch{
code: code,
pattern: regex,View on GitHub (pinned to 7bedaf55a0)
Solutions
- Make the first field of the redirect line a pure-digit status code (e.g. 301, 302, 307, 308).
- Check that the line has exactly three whitespace-separated fields: code, pattern, target — a missing field shifts values left.
- If porting from Apache/nginx configs, rewrite the directive to this library's 'CODE PATTERN TARGET' format.
- Validate the code string with a regexp like ^\d{3}$ before calling New in tests or tooling.
Example fix
// before
rewrite.New([]rewrite.RedirectMatchLine{"30x /old(.*) /new/$1"})
// after
rewrite.New([]rewrite.RedirectMatchLine{"301 /old(.*) /new/$1"}) Defensive patterns
Strategy: validation
Validate before calling
var codeRe = regexp.MustCompile(`^\d+$`)
if !codeRe.MatchString(strings.Fields(line)[0]) {
return fmt.Errorf("invalid redirect line %q: code must be digits", line)
} Try / catch
if err := rewrite.New(lines); err != nil {
var perr *parseError
if errors.As(err, &perr) { /* fix config line */ }
log.Fatalf("redirect config invalid: %v", err)
} Prevention
- Keep every redirect line as exactly three fields: digits, pattern, target.
- Add a config lint/test that parses all redirect lines at startup in CI.
- When porting Apache RedirectMatch rules, rewrite them to this format first.
When it happens
Trigger: Registering a Rewrite redirect rule via rewrite.New (or RedirectMatch directive) where the first whitespace-separated field is not purely numeric, e.g. '30x /old /new' or 'redirect /old /new' (missing the code).
Common situations: Typo in a redirect config line, copying an Apache-style RedirectMatch line without adjusting the syntax, or a rule line where the code field was accidentally omitted so pattern/target shift left.
Related errors
- redirect match: status code digits: %s: %v
- redirect match: loop detected: pattern: %s vs target: %s
- empty form
- errors joined from param parser: strings.Join(p.errors, "\n"
- parameter is not alphabetical
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/b02140122f43c24f.
Report an issue: GitHub.