I would like to set the value of the Authorization
header to be the same as the value of the CustomAuthorization
header. Or in other words, rename the header. According to the docs, it sounds like I should be able to do it like this:
RequestHeader set Authorization %{HTTP:CustomAuthorization}
But that produces an error:
# apachectl configtest
AH00526: Syntax error on line 7 of /etc/apache2/sites-enabled/01-netbox.conf:
Unrecognized header format %
It works if I set it to a static value like this:
RequestHeader set Authorization foo
I’m using Apache/2.4.52 (Ubuntu)
2
Answers
I figured it out, this works:
The error you’re encountering is because the
%{HTTP:CustomAuthorization}
syntax is not supported in the RequestHeader directive of Apache 2.4. To achieve your desired outcome of setting the value of the Authorization header to be the same as the value of the CustomAuthorization header, you can use the mod_rewrite module instead.Here’s an example of how you can rewrite the header using mod_rewrite:
apache
Copy
This code snippet will capture the value of the CustomAuthorization header and assign it to the HTTP_AUTHORIZATION environment variable. The HTTP_AUTHORIZATION environment variable is used by Apache to set the value of the Authorization header.
Place this code snippet in your Apache configuration file (e.g., 01-netbox.conf) within the appropriate context (e.g., or ). Make sure that the mod_rewrite module is enabled by running a2enmod rewrite and then restart Apache for the changes to take effect.
After implementing this configuration, the value of the Authorization header should be the same as the value of the CustomAuthorization header in the incoming request.
Please note that if you’re using a different Apache version or have any specific configuration requirements, the above solution might need adjustments accordingly.