This answer is inspired by Setting HTTP request headers and IIS server variables in the IIS documentation. They do something similar, but oddly it avoids detecting whether the original URL was accessed with HTTP or HTTPS.
First, you need to have administrative access to your IIS server in order to set up a new allowed server variable in the URL Rewrite module. This is described in the linked article, but here are the basic steps:
- In IIS Manager, navigate to your web site or application folder.
- Open the URL Rewrite feature.
- In the Actions pane, click "View Server Variables...", then click "Add..."
- Enter a name for your server variable.
- If you want to access it as an HTTP header, prefix it with
HTTP
. For example, HTTP_X_MY_HEADER
is accessible as the X-MY-HEADER
header.
Then, in your rewrite rule, set the server variable value to {CACHE_URL}
. You can do this through the UI, or directly in web.config, as shown below.
NOTE: be sure to set your match, conditions, and actions as needed.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="original URL sample" stopProcessing="true">
...
<serverVariables>
<set name="HTTP_X_MY_HEADER" value="{CACHE_URL}" />
</serverVariables>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
The resulting header will explicitly include the port number, e.g. http://foo.example:80/bar
, so you may need to deal with that depending on your needs.