RequestHeader with Apache environment variable

Late but still, I've just dealt with the same issue, and this worked for me:

RequestHeader set X_FORWARDED_PROTO 'https' env=HTTPS

The documentation says:

When the RequestHeader directive is used with the add, append, or set argument, a fourth argument may be used to specify conditions under which the action will be taken. If the environment variable specified in the env=... argument exists (or if the environment variable does not exist and env=!... is specified) then the action specified by the RequestHeader directive will take effect. Otherwise, the directive will have no effect on the request.

While the HTTPS environment variable is only set when the request is made through SSL.


You don't want that; it'd set your header to "HTTP/1.1" (even on an https request) - probably not terribly useful to whatever you're passing to.

You have different VirtualHost blocks for http and https; just hardcode the RequestHeader setting in each.

<VirtualHost *:80>
    RequestHeader set X-Forwarded-Proto "http"
    ...
</VirtualHost>

<VirtualHost *:443>
    RequestHeader set X-Forwarded-Proto "https"
    ...
</VirtualHost>