【问题标题】:Why is the cache busting rule declared in web.config being ignored?为什么在 web.config 中声明的缓存破坏规则被忽略?
【发布时间】:2012-06-25 02:20:22
【问题描述】:

我正在尝试使用HTML 5 Boilerplate project 中的重写规则来绕过浏览器缓存(也称为缓存破坏):

<rewrite>
    <rules>
        <rule name="Cachebusting">
            <match url="^(.+)\.\d+(\.(js|css|png|jpg|gif)$)" />
            <action type="Rewrite" url="{R:1}{R:2}" />
        </rule>
        <rule name="Remove WWW" stopProcessing="true">
            <match url="^(.*)$" />
            <conditions>
              <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
            </conditions>
            <action type="Redirect" url="http://chewsy.com{PATH_INFO}" redirectType="Permanent" />
        </rule>
    </rules>
</rewrite>

如果我尝试使用 /css/all.123456.css 访问我的 css,它找不到文件并报告它正在寻找 /css/all.123456.css(不重写)。我尝试注释掉 "Remove WWW" 规则,看看这是否存在冲突,但行为相同。

任何想法为什么不应用此规则并重写 URL?

更新:我在 VS2010 中为我的网络服务器使用这些设置:

【问题讨论】:

    标签: asp.net html web-config html5boilerplate


    【解决方案1】:
    <match url="^(.+)\.\d+\.(js|css|png|jpg|gif)$" />
    <action type="Rewrite" url="{R:1}.{R:2}" />
    

    我想你想得到/css/all.css,如果没有,发布想要的结果......

    编辑: VS 内部开发服务器 (Cassini) 不支持 IIS URL 重写模块,您必须为此使用 IIS (Express) 或某些第三方组件 (http://urlrewriter.net/) ...

    【讨论】:

    • 这并没有改变任何东西。结果相同,这意味着 /css/all.123456.css 没有解析为 /css/all.css
    • @TMC - 它解决了什么
    • 我得到一个 404。看起来它根本没有被重写。
    • @TMC 您应该在错误页面的查询字符串中看到不存在的路径(或在其文本中,不知道您是如何处理它的),它是什么 - 和 /css/all.css仍然存在(也许你是从缓存中获取的)
    • 它抛出 404。错误页面显示 The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. 并且“请求的 URL”被列为 /css/all.2012062401.css/css/all.css确实存在。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-05
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多