1

I have two virtual directories in an Azure Web App and confirmed that they're working properly as application directories.

The root of the Web App contains nothing except a web.config file with two rewrite rules that cause subdomains to point to subfolders like this:

<rule name="App1 Subdomain Redirect to SubFolder">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^app1.myservice\.net$" />
    </conditions>
    <action type="Rewrite" url="/app1/{R:0}" />
</rule>   

<rule name="App2 Subdomain Redirect to SubFolder">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^app2.myservice\.net$" />
    </conditions>
    <action type="Rewrite" url="/app2/{R:0}" />
</rule>

(I understand this could be written more efficiently - I'm trying to remove as many variables as possible.)

In each of the virtual directories I have another web.config that contains a single rule to add an extension:

<rule name="Add Extension">
    <match url=".*" negate="false" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
    </conditions>
    <action type="Rewrite" url="{R:0}.ashx" />
</rule>

The problem I'm experiencing is that the "Add Extension" rule is never processed.

If I remove the rule from the virtual directory's config file and put it into the root's, all is well. (If I only do this for one virtual directory, it works fine for that directory while the other does not. If I do it for both, then all rules get processed.)

If I remove the "Add Extension" rule and try other rules the other rules do not get processed, which indicates to me this is not a problem specific to this particular rule.

If I remove all rules from the root's config, all rules in the virtual directories get processed.

My question is, has anyone else experienced this and what have they done as a workaround?

It's my understanding that rules should cascade from root to virtual directories in the same way other configuration settings do.

Searches have not been helpful.

Anand seems to have experienced the same problem on a non-Azure IIS site but no answer was proposed: http://forums.iis.net/t/1178488.aspx

Zielu1's question is somewhat similar but again did not receive a response: IIS URL rewrite in child virtual directory not redirecting

There are a fair number of other questions about rewrites, mostly about syntax and getting them to work in general, but few about virtual directory inheritance of rules.

Thanks for the help.

Community
  • 1
  • 1
John Clegg
  • 348
  • 3
  • 6

1 Answers1

0

Try it matching full subdirectory paths

<rule name="Add Extension">
    <match url="/MySubDirectory/.*" negate="false" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
    </conditions>
    <action type="Rewrite" url="{R:0}.ashx" />
</rule>
JuanK
  • 2,056
  • 19
  • 32
  • Juan, I tried your suggestion in the virtual folder config and it didn't work. Just to be sure I typed it right I then placed it in the root folder config and it did work. – John Clegg Oct 08 '15 at 22:05