iis - 根据文件类型添加自定义标题

标签 iis web-config http-headers iis-7.5

我们正在尝试为 IIS 7.5 中的站点地图文件添加自定义 header (X-Robots-Tag)。但是,IIS 似乎不支持基于文件类型或通配符(仅子文件夹)的自定义 header 。

我们可以通过 Web.config 为 *.xml.gz 文件添加自定义 header 吗?

我们希望避免通过代码或在我们的负载均衡器上进行自定义。

最佳答案

您可以使用 IIS UrlRewrite module并添加自定义出站规则以配置自定义 header 。这是您可能要使用的示例规则:

  <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>

更多信息:UrlRewrite documentation

关于iis - 根据文件类型添加自定义标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9522348/

相关文章:

iis - 信任来自 IIS 的自签名证书

php - 启用 Windows 身份验证的 iis 访问网络共享

asp.net - 一种#if(调试符号),但用于 web.config 文件

web-config - web.config : maxRequestLength not taking effect

iis - 当 URL 以点结尾时重定向到自定义 404 页面

servlets - Websphere 8.5 Liberty Profile - Servlet API setLocale

防火墙背后的 WCF WebService/IIS 托管和配置问题

jquery - DataTables 在本地工作,托管时出现 404 和 Ajax 错误

http-headers - 内容长度已经存在错误soapUI 4.5.1

http - 检测浏览器用户代理伪造