根据文件类型添加自定义标头 [英] Add custom header based on file type
本文介绍了根据文件类型添加自定义标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们正在尝试为IIS 7.5中的站点地图文件添加自定义标题(X-Robots-Tag)。但是,IIS似乎不支持基于文件类型或通配符(仅限子文件夹)的自定义标头。
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).
我们是否可以仅为* .xml添加自定义标头。 gz文件通过Web.config?
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.
推荐答案
您可以使用 IIS UrlRewrite模块和添加自定义出站规则以配置自定义标头。以下是您可能要使用的示例规则:
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>
这篇关于根据文件类型添加自定义标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文