3
votes

I'm trying to use the URL Rewrite module of IIS to redirect my users to Another application/site on the IIS server, however I need to retain the custom HTTP headers included for authentication purposes, but they seem to get lost in the rewrite. Does anyone know if, and how, the rules must be setup in order to include those HTTP headers when sending the user on his/her merry way?

This is the rule, as per today:

        <rewrite>
        <rules>
            <rule name="API Redirect">
                <match url="/API/Tracker/\d{1,2}.\d{1,2}/(.*)" />
                <action type="Rewrite" url="/Tracker/1.0/tracker.svc/{R:1}" appendQueryString="false" logRewrittenUrl="true" />
            </rule>
        </rules>
    </rewrite>
3

3 Answers

1
votes

I was having problems with something similar. I kept losing some Cache-Control headers that I was attempting to use.

The below was able to help me out. I'm not sure how you would go about doing this if you wanted your headers to have dynamic values, but this worked for me.

I came to this while using IIS 8.5.

Go into your site, and in IIS > HTTP Response Headers

Then add the custom header that you would want to use and the value. Again, I'm not sure how you would go about doing this if you needed the header to have a dynamic value.

0
votes

Have you tried to enable querystring?

appendQueryString="true"
0
votes

Just wanted to share a solution that would apply a custom http header based on the current URL - not sure if this is exactly what you are looking for but it worked for me when I wanted to add a X-Robots-Tag to all requests to our admin-page.

In web.config, add this:

<location path="admin">
    <system.webServer>
      <httpProtocol>
          <customHeaders>
              <remove name="X-Robots-Tag" />
              <add name="X-Robots-Tag" value="noindex"/>
          </customHeaders>
    </httpProtocol>
 </system.webServer>
</location>