Rewrite URL IIS Https rule breaks after adding new rule for JavaScript Versioning

32 Views Asked by At

I had a rule Http to Https redirect which was working fine.

But now I am adding new rule in the same tag for IIS rewrite rule to add query string to .js references in the entire MVC website pages. Now what happens is that the previous rule which was applied is also not working after adding the new rule as well as new rule also does not work.

Below is the rule from HTTP to Https redirect and this code works fine.

    <location path="." allowOverride="true" inheritInChildApplications="false">
        <system.webServer>
            <rewrite>
            <rules>
                <rule name="httpsRedirect" stopProcessing="true">
                    <match url="(.*)"/>
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$"/>
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}
                                                {REQUEST_URI}"/>         
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
    </location>

What I am doing wrong in the below code? Please suggest.

<location path="." allowOverride="true" inheritInChildApplications="false">
<system.webServer>
    <rewrite>
        <rules>
            <rule name="httpsRedirect" stopProcessing="true">
                <match url="(.*)"/>
                <conditions>
                    <add input="{HTTPS}" pattern="^OFF$"/>
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}"/>
            </rule>
            <rule name="JSVersioning" stopProcessing="true">
                <match url="(.*).js" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                     <add input="{REQUEST_FILENAME}" matchType="IsFile" />
                     <add input="{QUERY_STRING}" pattern="version=3911" negate="true" />
                </conditions>
                <action type="Redirect" url="{R:1}.js?version=3911" redirectType="Permanent" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>
0

There are 0 best solutions below