web.config: rewrite only if *rewritten* path exists RRS feed

  • Question

  • User-1930884629 posted

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

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

    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?

    Monday, February 24, 2014 10:08 PM

All replies

  • User1938476581 posted


    I have tested it. It maybe impossible to achieve this only with url rewrite module. I try creating a custom error page which will redirect to orignal url. But then the orignal url request will be matched by url rewrite rule again. So this will result loop issue.

    Wednesday, February 26, 2014 12:23 AM