web.config - 忽略特定文件夹的重写

web.config - Ignore rewrite for specific folder

根目录是一个 WordPress 站点。我需要忽略 URL 重写文件夹 "app",因为我在该文件夹上托管了一个虚拟目录 .NET App。

http://www.mywebsite.com/app

URL 重写 web.config 中的规则部分有效。如果 URL link 到 .NET 应用程序中的静态文件或文件夹,它就可以工作。如果 URL link 到路由 url,它会失败。如何修复?

例如这个URL:

mywebsite.com/app/Login

应该路由到

mywebsite.com/app/Login.aspx

但是,它被 WordPress 捕获并显示 404 未找到错误。

如果 URL 是这样输入的,那么它运行正常:

mywebsite.com/app/Login.aspx

这是根站点 (wordpress) 的 web.config

<rule name="WordPress: http://www.mywebsite.com" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{R:0}" pattern="^/app" negate="true" />
<add input="{R:0}" pattern="^/app/(.*)$" negate="true" />
<add input="{R:0}" pattern="^app/(.*)$" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule>

这是 .NET 应用程序中 URL 路由的代码

public class Global : System.Web.HttpApplication
{
    protected void Application_Start(object sender, EventArgs e)
    {
        RouteTable.Routes.MapPageRoute("login", "login", "~/login.aspx");
    }
}

我使用这条线成功解决了问题:

<add input="{HTTP_URL}" pattern="*/app" negate="true"/>

有一个很好的 reference by Microsoft 详细解释了这些规则的工作原理。