How to dynamically set HTTP Header in Apache 2.2?

Solution 1:

The FOOBAR in %{FOOBAR}e should be an environment variable, but HTTP_HOST is a server variable.

If you really want to do that, you may try:

RewriteRule (.*) $1 [E=custom_host:%{HTTP_HOST}]
RequestHeader set X-Custom-Host-Header "%{custom_host}e"

or

RewriteCond %{HTTP_HOST} (.*)
RewriteRule (.*) $1 [E=custom_host:%1]
RequestHeader set X-Custom-Host-Header "%{custom_host}e"

or

SetEnvIf Host (.*) custom_host=$1
RequestHeader set X-Custom-Host-Header "%{custom_host}e"

All untested.

Not sure of the first one, but the second and third one should work.