我正在尝试使用 301 响应和缓存过期 header 在 IIS 8.5 中开发“半永久”重定向,可能是具有合理过期时间的 max-age 或缓存控制。然而 IIS 的 URL 重写 doesn't seem to support将响应 header 添加到重定向规则。我看到如何在更大范围内影响缓存,like this ,但不是如何将它们应用于单个重定向。 IE。:
<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;路径将在一两个月内保持不变,但在那之后可能会改变。直301会cache permanently在某些浏览器中。 302/307 将导致虚 URL 为 indexed ,这会弄乱我的 SEO。
最佳答案
缓存响应 header 进入出站规则:
<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 截图:
这将帮助您避免使用 301 permanent redirects 无法消除的恐惧。 .我鼓励你阅读这篇优秀的文章。
随着信用
http://www.gillsoft.ie/using-url-rewrite-to-improve-your-site-performance-001
关于redirect - 带有缓存响应 header 的 IIS 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35047484/