【问题标题】:web.config - Ignore rewrite for specific folderweb.config - 忽略特定文件夹的重写
【发布时间】:2019-05-07 20:37:00
【问题描述】:

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

http://www.mywebsite.com/app

web.config 中的 URL 重写规则部分起作用。如果 URL 链接到 .NET 应用程序中的静态文件或文件夹,则它可以工作。如果 URL 链接到路由 url,则失败。如何解决?

例如这个网址:

mywebsite.com/app/Login

应该被路由到

mywebsite.com/app/Login.aspx

但是,它被 WordPress 捕获并显示 404 not found 错误。

如果 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 App 中 URL 路由的代码

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

【问题讨论】:

    标签: c# asp.net wordpress url-rewriting web-config


    【解决方案1】:

    我设法通过使用这条线解决了这个问题:

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

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

    【讨论】:

      猜你喜欢
      • 2017-07-25
      • 2018-05-18
      • 1970-01-01
      • 1970-01-01
      • 2014-02-05
      • 2019-10-18
      • 2012-02-04
      • 1970-01-01
      • 2020-06-19
      相关资源
      最近更新 更多