Reputation: 1799
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?
Upvotes: 4
Views: 1155
Reputation: 1852
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.
Upvotes: 3