Apache RewriteRule with a RewriteMap variable substitution for the VAL argument to environment variable
- by Eric
I have an Apache server that serves up binary files to an application (not a browser).
The application making the request wants the HTTP Content-MD5 header in HEX format. The default and only option within Apache is Base64. If I add "ContentDigest on" to my VirtualHost, I get this header in Base64.
So I wrote a perl script, md5digesthex.pl, that gives me exactly what I want: MD5 in HEX format but I'm struggling with the RewriteRule to get my server to send the result.
Here is my current Rewrite recipe:
RewriteEngine on
RewriteMap md5inhex prg:/www/download/md5digesthex.pl
RewriteCond %{REQUEST_URI} ^/download/(.*)
RewriteRule ^(.*) %{REQUEST_URI} [E=HASH:${md5inhex:$1}]
Header set Content-MD5 "%{HASH}e" env=HASH
The problem is that I can't seem to set the HASH environment variable based on the output of the md5inhex map function. It appears this behavior is not supported and I'm at a lost as to how to formulate this...