views:

75

answers:

2

I have created a rewrite rule for javascript and css versioning in IIS 7. The rule is defined as follows:

<rewrite>
   <rules>
     <rule name="Js/Css Cache Rewrite" stopProcessing="true">
       <match url="(.+/public/(javascript|css)/(Debug|Release)/.+\.)\d+\.(js|css)" />
       <action type="Rewrite" url="{R:1}{R:4}" logRewrittenUrl="true" />
     </rule>
   </rules>
 </rewrite>

When I manually test the url against the regex it matches. The url follows this pattern: http://mytestsite.com/public/javascript/Release/SomeDir/jsfile.20100915140743.js

Any ideas on what I could be missing for the configuration?

A: 

Your regex starts out with (.+/public/, which translates to "one or more characters, followed by /public/". Your URL as passed to you by IIS starts out with either /public/ or public/, neither of which match your regex. You probably need somthing like ((^|.*/)public/ instead.

Gabe
If the URL passed in is either /public/... or public/... wouldn't this be simpler? i.e. (^|/)public/
nickyt
nickyt: Yes, it would be simpler, but the URL could also be "/blah/blah/blah/public/..."
Gabe
Yeah you're close to what the problem was. The incoming url ended up being "public/..." because of the level in IIS where it was configured. If I configured at a higher level then it had the full url. I changed my regex to the following: (.*public/(javascript|css)/(Debug|Release)/.+\.)\d+\.(js|css)
Keith Rousseau
A: 

The incoming url ended up being "public/..." because of the level in IIS where it was configured. If I configured at a higher level then it had the full url. I changed my regex to the following: (.*public/(javascript|css)/(Debug|Release)/.+.)\d+.(js|css) and it works.

Keith Rousseau