Question

I want to do a rewrite from http://example.com/assets/file.ext to /sites/example.com/assets/file.ext only if that rewritten path exists. I can do it more broadly like so:

  <rules>
    <rule name="assets" stopProcessing="true">
      <match url="^assets/(.+)$" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^(www\.)?(.*)$" />
      </conditions>
      <action type="Rewrite" url="sites/{C:2}/assets/{R:1}" />
    </rule>
  </rules>

but when I add a condition <add input="{REQUEST_FILENAME}" matchType="IsFile" /> it will try to match a file at the original path.

Can this be done?

Was it helpful?

Solution

The rule you want is I believe approximately this:

<add input="{APPL_PHYSICAL_PATH}sites\{C:2}\assets\{R:1}" matchType="IsFile" />

This has to come after the host condition, obviously, so that the backreference is available.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top