我们正在尝试为 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/