Web.config: rewrite only if * rewritten * path exists

I want to do rewriting from http://example.com/assets/file.extto /sites/example.com/assets/file.extonly if this rewritten path exists. I can do it more broadly, for example:

  <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 the condition <add input="{REQUEST_FILENAME}" matchType="IsFile" />, it will try to map the file to the original path.

Can this be done?

+3
source share
1 answer

The rule you want is something like this:

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

This should happen after the state of the host, it is obvious that the available link is available.

+2
source

All Articles