【问题标题】:IIS redirect with cache response header带有缓存响应标头的 IIS 重定向
【发布时间】:2016-05-05 00:02:56
【问题描述】:

我正在尝试在 IIS 8.5 中使用 301 响应以及缓存过期标头开发“半永久”重定向,可能是具有合理过期的 max-age 或缓存控制。但是 IIS 的 URL Rewrite 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 的;路径将在一两个月内保持不变,但之后可能会发生变化。在某些浏览器中,直接 301 将 cache permanently。 302/307 将导致虚 URL 为 indexed,这会扰乱我的 SEO。

【问题讨论】:

    标签: redirect caching iis web-config


    【解决方案1】:

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

        <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>
    

    结果:

    提琴手截图:

    这将帮助您避免使用301 permanent redirects 无法消除的恐惧。我鼓励您阅读这篇出色的文章。

    归功于 http://www.gillsoft.ie/using-url-rewrite-to-improve-your-site-performance-001

    【讨论】:

    • 谢谢,这正是我想要的!这些文章中的许多 cmets 建议改用 302,这会损害 SEO。这个解决方案似乎是正确的妥协。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-19
    相关资源
    最近更新 更多