1041: Invalid Request Rewrite: Invalid Header ValueError 1041 occurs when a Cloudflare Transform Rule sets a header to a value that violates HTTP header specifications. Header values must conform to RFC 7230 — they cannot contain certain control characters, null bytes, or newlines. If a dynamic expression in a Transform Rule produces a value with illegal characters, Cloudflare returns 1041 instead of forwarding the malformed request to the origin.
Error 1041: Invalid Request Rewrite: Invalid Header ValueGET /api/items HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0
Accept: text/htmlHTTP/1.1 409 Conflict
Server: cloudflare
CF-RAY: 7c9d0e1f2a3b4568-VNO
Content-Type: text/html
<!doctype html>
<html>
<head>
<title>www.example.com | Error 1041</title>
</head>
<body>
<h1>Error 1041: Invalid request rewrite: invalid header value</h1>
<p>A Cloudflare Transform Rule set a header to an invalid value. Please contact the site owner.</p>
</body>
</html>Review the Transform Rule's expression that generates the header value. Test what it evaluates to for the failing request.
If the header value comes from a dynamic source (like a request field), ensure it is sanitized to remove control characters and newlines before setting it as a header.
If the header value must contain special characters, URL-encode them first so the raw header value contains only valid characters.
The Transform Rule's expression generates a value containing control characters (like \r, \n, \0) that are not allowed in HTTP headers.
The rule tries to set a header value containing raw binary data or improperly encoded content that violates HTTP header formatting rules.
The expression evaluates to an empty string for a header that requires a non-empty value.
A Transform Rule attempted to modify a request header that Cloudflare does not allow to be changed.
A Cloudflare Transform Rule or rewrite produced an invalid URI path.
A Cloudflare Transform Rule's expression could not be evaluated at runtime.
This reference was compiled from official RFCs, protocol specifications, and hands-on troubleshooting experience. AI tools were used primarily for formatting and organizing the content on the page.