我们正在尝试为IIS 7.5中的站点地图文件添加自定义标头(X-Robots-Tag)。但是,IIS似乎不支持基于文件类型或通配符(仅限子文件夹)的自定义标头。
我们可以通过Web.config为<.xml.gz文件添加自定义标头吗?
我们希望避免通过代码或负载均衡器进行自定义。
答案 0 :(得分:42)
您可以使用IIS UrlRewrite module并添加自定义出站规则来配置自定义标头。以下是您可能想要使用的示例规则:
<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>