DrewG
DrewG

Reputation: 253

IIS UrlRewrite for reverse proxy only working if folder exists on primary website

I've got two websites on the same box and I want to reverse proxy a folder on one to the other. It is only working for directories if I create the directory on the parent website.

so i want http://site/odata/Books

to go to http://myodatasite/odata/Books

Pretty straightforward, but it is not working unless I go to wwwroot/site and create the /odata/Books folders there. If I do this, the rewrite works. If I call /odata/Authors, again it will 404 unless I create an Authors folder.

It seems like I need to have a wilcard mapping in place in IIS or something else is causing the rewrite to fail. I have tried adding a wildcard mapping pointing to aspnet_isapi and had no changes, possibly because of integrated mode but I haven't found anything that is helpful online yet for this.

Does anyone know why my rewrite is not working for directories but a redirect works fine?

<rewrite>
      <rules>
        <!-- Does Not Work unless folders exist on current site! -->
        <rule name="OdataRoutes" stopProcessing="true">
          <match url="^odata/(.*)" />
          <action type="Rewrite" url="http://myodatasite/odata/{R:1}" />
        </rule>
        <!-- Works -->
        <rule name="OdataRoutes2" stopProcessing="true">
          <match url="odata2/(.*)" />
          <action type="Redirect" url="http://myodatasite/odata/{R:1}" />
        </rule>
        <!-- Works -->
        <rule name="OdataRoutes3" stopProcessing="true">
          <match url="(.*)\.odata" />
          <action type="Rewrite" url="http://myodatasite/odata/{R:1}" />
        </rule>
</rewrite>

Upvotes: 1

Views: 524

Answers (1)

DrewG
DrewG

Reputation: 253

Looks like it wasn't the mappings at all. Turning on Failed request tracing and monitoring the successful request and the failed request, it seemed the directory rewrite was being passed from ARR to the MvcHandler. Not sure why the redirect wasnt and the rewrite was, but after seeing that, the fix was pretty easy.

routes.IgnoreRoute("odata/{*pathInfo}");

Upvotes: 1

Related Questions