locked
URLRewrite for CSS and JS RRS feed

  • Question

  • User94323121 posted

    Hi,

    I want to versioning my .js and css files in IÌS with a rewriterule

    I use this :

    <script src="js/test-getdatetime-js-file-to-uncache.<%=System.IO.File.GetLastWriteTime(Request.PhysicalApplicationPath + "\js\test-getdatetime-js-file-to-uncache.js").ToString("yyMMddhhmmss")%>.js" type="text/javascript"></script>

    So i got, for example :

    <script src="js/test-getdatetime-js-file-to-uncache.110408025352.js" type="text/javascript"></script>
     

    I want to create a rewrite rule for the .js file but it's not working. Im a newbie with REGEX.

    I try this but it's not working :

    <rule name="NoCacheOnModified" stopProcessing="true">
                        <match url="^js/test-getdatetime-js-file-to-uncache.[0-9]+.js$" />
                        <action type="Rewrite" url="js/{R:1}" />
                    </rule>

    What's the correct rule for this?

    Thanks

    Friday, April 8, 2011 4:01 PM

Answers

  • User94323121 posted
    After many tests i got it!
    <rule name="NoCacheOnModified" stopProcessing="true">
       <match url="^(css|js)/(.*)\.[0-9]+\.(.*)$" />
       <action type="Rewrite" url="/{R:1}/{R:2}.{R:3}" />
    </rule>
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 11, 2011 10:18 AM