【发布时间】:2015-10-08 20:28:49
【问题描述】:
我在 Azure Web 应用中有两个虚拟目录,并确认它们作为应用程序目录正常工作。
Web App 的根目录只包含一个 web.config 文件,其中包含两个重写规则,这些规则导致子域指向子文件夹,如下所示:
<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>
(我知道这可以更有效地编写 - 我正在尝试删除尽可能多的变量。)
在每个虚拟目录中,我都有另一个 web.config,其中包含添加扩展的单个规则:
<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>
我遇到的问题是“添加扩展”规则从未得到处理。
如果我从虚拟目录的配置文件中删除规则并将其放入根目录中,一切都很好。 (如果我只对一个虚拟目录执行此操作,则该目录可以正常工作,而另一个则不能。如果我对两个虚拟目录都执行此操作,则所有规则都会得到处理。)
如果我删除“添加扩展”规则并尝试其他规则,则其他规则不会得到处理,这表明这不是特定于该特定规则的问题。
如果我从根的配置中删除所有规则,虚拟目录中的所有规则都会得到处理。
我的问题是,有其他人经历过这种情况吗?他们做了什么作为解决方法?
我的理解是规则应该像其他配置设置一样从根目录级联到虚拟目录。
搜索没有帮助。
Anand 似乎在非 Azure IIS 站点上遇到了同样的问题,但没有提出答案:http://forums.iis.net/t/1178488.aspx
Zielu1 的问题有点类似但同样没有得到回复:IIS URL rewrite in child virtual directory not redirecting
还有很多关于重写的其他问题,主要是关于语法和如何让它们正常工作,但很少有关于规则的虚拟目录继承的问题。
感谢您的帮助。
【问题讨论】:
标签: azure url-rewrite-module virtual-directory