h5bp / server-configs-iis

IIS Web.Config Boilerplates
MIT License
336 stars 84 forks source link

CacheBusting rewrite rule is missing file exists check #22

Closed unger closed 8 years ago

unger commented 9 years ago

The .htaccess version of this rewrite rule contains a check that the requested file does not exist before rewriting (the !-f part in RewriteCond %{REQUEST_FILENAME} !-f).

This check is needed to avoid rewriting if the file exists on the server. Otherwise it will return 404, example below. jquery-1.11.3.js => jquery-1.11.js

This can be solved by using a condition of the rewiterule, full example below:

<rewrite>
    <rules>
        <rule name="Cachebusting">
            <match url="^(.+)\.\d+(\.(js|css|png|jpg|gif)$)" />
            <conditions>
              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            </conditions>
            <action type="Rewrite" url="{R:1}{R:2}" />
        </rule>
    </rules>
</rewrite>
ChrisMcKee commented 9 years ago

Thanks i'll add that in.