Apache RewriteRule with a RewriteMap variable substitution for the VAL argument to environment variable

Posted by Eric on Server Fault See other posts from Server Fault or by Eric
Published on 2010-12-23T02:07:42Z Indexed on 2010/12/23 2:56 UTC
Read the original article Hit count: 354

Filed under:
|
|

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...

© Server Fault or respective owner

Related posts about apache

Related posts about rewriterule