{"record":{"id":"3a3cbd2a7dccd17c","repo":"kataras/iris","slug":"redirect-match-invalid-line-s","errorCode":null,"errorMessage":"redirect match: invalid line: %s","messagePattern":"redirect match: invalid line: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"middleware/rewrite/rewrite.go","lineNumber":284,"sourceCode":"\n\tisRelativePattern bool\n\tnoRedirect        bool\n}\n\nfunc (r *redirectMatch) matchAndReplace(src string) (string, bool) {\n\tif r.pattern.MatchString(src) {\n\t\tif match := r.pattern.ReplaceAllString(src, r.target); match != \"\" {\n\t\t\treturn match, true\n\t\t}\n\t}\n\n\treturn \"\", false\n}\n\nfunc parseRedirectMatchLine(s string) (*redirectMatch, error) {\n\tparts := strings.Split(strings.TrimSpace(s), \" \")\n\tif len(parts) != 3 {\n\t\treturn nil, fmt.Errorf(\"redirect match: invalid line: %s\", s)\n\t}\n\n\tcodeStr, pattern, target := parts[0], parts[1], parts[2]\n\n\tfor i, ch := range codeStr {\n\t\tif !isDigit(ch) {\n\t\t\treturn nil, fmt.Errorf(\"redirect match: status code digits: %s [%d:%c]\", codeStr, i, ch)\n\t\t}\n\t}\n\n\tcode, err := strconv.Atoi(codeStr)\n\tif err != nil {\n\t\t// this should not happen, we check abt digit\n\t\t// and correctly position the error too but handle it.\n\t\treturn nil, fmt.Errorf(\"redirect match: status code digits: %s: %v\", codeStr, err)\n\t}\n\n\tregex := regexp.MustCompile(pattern)","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/middleware/rewrite/rewrite.go#L266-L302","documentation":"rewrite's parseRedirectMatchLine expects each redirect-match directive line to contain exactly three space-separated parts: status code, pattern, target. A line that splits into a different number of parts is rejected with this error quoting the whole line. It surfaces when building a RewriteEngine from a file or slice of redirect-match lines.","triggerScenarios":"A 'redirect match' line in the rewrite rules file (or passed to TestRedirectMatch/New) has missing or extra tokens — e.g. missing target, an unquoted URL containing spaces, or a stray trailing token.","commonSituations":"Hand-edited rewrite config files with typos, copy-pasted Apache-style directives with extra flags like [R=301], or target URLs that contain unencoded spaces.","solutions":["Make each line exactly: <statusCode> <pattern> <target>, e.g. `301 /old /new`.","Remove extra tokens (flags, comments on the same line, brackets) or percent-encode spaces inside URLs.","Use rewrite.TestRedirectMatch/parse on your rules file locally to find the offending line number before deploying."],"exampleFix":"// before\nredirect match 301 /old-path /new-path [R=301,L]\n\n// after\nredirect match 301 /old-path /new-path","handlingStrategy":"validation","validationCode":"parts := strings.Fields(line); if len(parts) != 3 { return fmt.Errorf(\"bad redirect line: %s\", line) }","typeGuard":"func isValidRedirectMatchLine(s string) bool { return len(strings.Fields(strings.TrimSpace(s))) == 3 }","tryCatchPattern":"_, err := rewrite.New(rules); if err != nil && strings.Contains(err.Error(), \"invalid line\") { log.Fatalf(\"rewrite rules: %v\", err) }","preventionTips":["Keep each redirect-match line to exactly: code pattern target.","Strip Apache-style flags like [R=301,L] and same-line comments.","Percent-encode spaces in URLs; run TestRedirectMatch on the rules file in CI."],"tags":["go","iris","rewrite","redirect","configuration-parsing"],"backgroundTag":"invalid-config-line","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}