IIS重定向缓存响应标头

时间:2016-01-27 20:34:53

标签: redirect caching iis web-config

我正在尝试使用301响应以及缓存过期标头在IIS 8.5中开发“半永久”重定向,可能是具有合理过期的max-age或缓存控制。但是IIS的URL重写doesn't seem to support将响应标头添加到重定向规则。我看到如何影响更大范围的缓存like this,而不是如何将它们应用于单个重定向。即:

<rule name="foo" stopProcessing="true">
  <match url="foo" />
  <conditions>
    <add input="{URL}" pattern="/foo($|\/$)" />
  </conditions>
  <action type="Redirect" url="http://domain.com/full_url_for_now" redirectType="Permanent" someParameterThatLetsMeSetResponseHeaders="max-age:3600"/>
</rule>

感谢您的任何建议。我猜测还有其他一些方法可以为单个规则/路径/等做这个,但没有运气找到它。如果不可能,那么我将不得不将缓存参数设置在更高的级别。

为什么:重定向是一个虚荣URL;路径将在一两个月内相同,但在此之后可能会发生变化。 Straight 301在某些浏览器中会cache permanently。 302/307将导致虚荣URL为indexed,这会弄乱我的搜索引擎优化。

1 个答案:

答案 0 :(得分:4)

缓存响应标头进入出站规则:

    <outboundRules>
          <rule name="Require clients to revalidationpermanent redirects">
                <match serverVariable="RESPONSE_Cache_Control" pattern=".*" />
                <conditions>
                    <add input="{RESPONSE_STATUS}" pattern="301" />
                </conditions>
                <action type="Rewrite" value="public, must-revalidate, max-age=0"/>
            </rule>

    </outboundRules>

结果:

Fiddler截图:

enter image description here

这将帮助您避免使用301 permanent redirects无法撤消的恐怖。我鼓励你阅读这篇优秀的文章。

有信用 http://www.gillsoft.ie/using-url-rewrite-to-improve-your-site-performance-001

相关问题