redirect - 带有缓存响应 header 的 IIS 重定向

标签 redirect caching iis web-config

我正在尝试使用 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 截图:

enter image description here

这将帮助您避免使用 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/

相关文章:

redirect - 使用不同主机名的带有斜杠的 nginx 别名重定向

Symfony 3,如何使用redirectToRoute方法传输URL参数

iis - Web 服务器是否可以向自己发出 HTTPS 请求?

java - ProcessBuilder.inheritIO() 将输出发送到错误的位置

node.js - node.js中位置和重定向之间的区别

ios - 是否有提供网络和磁盘缓存的 iOS 库?

asp.net - 如何仅在 ASP.Net 5 中防止某些文件的浏览器缓存?

java - 图像缓存和性能

asp.net - 为特定 URL 提供 app_offline.htm 时,将 http 状态 503 更改为 200

iis - 如何在 Azure VM 上设置 FTP