1040: Invalid Request Rewrite: Header Modification Not AllowedError 1040 occurs when a Cloudflare Transform Rule (specifically an HTTP Request Header Modification rule) tries to set, remove, or modify a header that is reserved or protected. Cloudflare restricts modifications to certain headers to maintain security and protocol compliance. Headers like Host, Content-Length, and certain Cloudflare-internal headers (CF-* prefix) cannot be modified through Transform Rules.
Error 1040: Invalid Request Rewrite: Header Modification Not AllowedGET /api/resource HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0
Accept: text/htmlHTTP/1.1 409 Conflict
Server: cloudflare
CF-RAY: 7b8c9d0e1f2a3457-TLL
Content-Type: text/html
<!doctype html>
<html>
<head>
<title>www.example.com | Error 1040</title>
</head>
<body>
<h1>Error 1040: Invalid request rewrite: header modification not allowed</h1>
<p>A Cloudflare Transform Rule attempted to modify a reserved HTTP header. Please contact the site owner.</p>
</body>
</html>In Rules > Transform Rules > Modify Request Header, check which headers your rules are trying to change. Compare against Cloudflare's list of reserved headers.
If you need to pass custom data to your origin, use a custom header name (like X-Custom-Header) instead of trying to modify reserved headers.
Review the Transform Rules documentation for the complete list of headers that cannot be modified.
The Transform Rule tries to set or remove a header like Host, Content-Length, Connection, or a CF-* internal header that Cloudflare protects from modification.
The rule targets hop-by-hop headers (Transfer-Encoding, Upgrade, Proxy-*) that are managed by the HTTP protocol layer and cannot be arbitrarily changed.
A Transform Rule set a request header to a value that is not valid per HTTP specifications.
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.