Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
562 views
in Technique[技术] by (71.8m points)

iis - Add custom header based on file type

We are trying to add a custom header (X-Robots-Tag) for sitemap files in IIS 7.5. However, it does not appear that IIS supports custom headers based on a file type or wildcard (only subfolders).

Can we add a custom header for only *.xml.gz files via Web.config?

We would like to avoid making the customization via code or on our load balancer.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use the IIS UrlRewrite module and add a custom outbound rule to configure the custom header. Here is a sample rule you may want to use:

  <system.webServer>
    <rewrite>
      <outboundRules>
        <rule name="Set custom HTTP response header">
          <match serverVariable="RESPONSE_X_Robots_Tag" pattern=".*" />
          <conditions>
            <add input="{REQUEST_URI}" pattern=".xml.gz$" />
          </conditions>
          <action type="Rewrite" value="The value you need for this header"/>
        </rule>
      </outboundRules>
    </rewrite>
  </system.webServer>

More info: UrlRewrite documentation


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...