简体   繁体   中英

URL Rewrite rule with HTTP headers

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>

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.

您是否尝试启用查询字符串?

appendQueryString="true"

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM