Apache RewriteRule用一个RewriteMapvariablesreplaceVAL参数给环境variables

我有一个Apache服务器,提供二进制文件到应用程序(而不是浏览器)。

发出请求的应用程序需要HEX格式的HTTP Content-MD5头文件。 Apache中的默认选项是Base64。 如果我将“ContentDigest on”添加到我的VirtualHost,我在Base64中得到这个头。

所以我写了一个Perl脚本,md5digesthex.pl,它给了我正是我想要的:hex格式的MD5,但我努力与RewriteRule让我的服务器发送结果。

这是我目前的重写配方:

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 

问题是,我似乎无法根据md5inhex映射函数的输出设置HASH环境variables。 看起来这种行为是不支持的,我在一个迷失,如何制定这个…

我认为更好的问题是,你为什么重新定义RFC已经定义了什么? 如果你试图超载Content-MD5头部,你可能只是使用不同的头部。 如果您正在尝试将其应用于您的程序,那么听起来像您的程序做错了事情,应该纠正。

编辑:所以我看了这个地方。 你能告诉我什么md5digesthex.pl的输出是? 它应该是一个空格分隔的值对,即:

 some/path/to/file somehash 

这听起来像键/值可能不匹配,因为这将做你想要的假设${md5inhex:$1}正确执行。 你可以尝试做什么,进行testing,设置一个虚拟variables; 即:

 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 RewriteRule ^(.*)$ - [E=TEST_HASH:${md5inhex:somekey}] Header set TestingHeader "%{TEST_HASH}e" env=TEST_HASH 

你可以使用像curl -I <server>/<path>来validation它的设置。 我可以validation使用格式正确的RewriteMap,这将正确设置您的信息。