问题描述
根是一个 WordPress 网站.我需要忽略文件夹app"的 URL 重写,因为我在该文件夹上托管了一个虚拟目录 .NET App.
The root is a WordPress site. I need to ignore URL rewrite for a folder "app", as I hosted a virtual directory .NET App on that folder.
http://www.mywebsite.com/app
web.config 中的 URL 重写规则部分起作用.如果 URL 链接到 .NET 应用程序中的静态文件或文件夹,则它有效.如果 URL 链接到路由 url,则失败.如何修复?
URL Rewrite rules in web.config works partially. If the URL link to a static file or folder in the .NET app, it works. If the URL link to a routed url, it fails. How to fix?
例如这个网址:
mywebsite.com/app/Login
应该被路由到
mywebsite.com/app/Login.aspx
但是,它被 WordPress 捕获并显示 404 not found 错误.
but, it is captured by WordPress and display a 404 not found error.
如果 URL 是这样输入的,那么它运行正常:
if the URL is entered as this, then it runs ok:
mywebsite.com/app/Login.aspx
这是根站点 (wordpress) 的 web.config
Here is the web.config at root site (wordpress)
<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路由的代码
This is the code for URL routing in the .NET App
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapPageRoute("login", "login", "~/login.aspx");
}
}
推荐答案
我通过使用这一行设法解决了这个问题:
I managed to solve the problem by using this line:
<add input="{HTTP_URL}" pattern="*/app" negate="true"/>
有一个很好的 Microsoft 引用,详细解释了这些规则的工作原理.
There is a nice reference by Microsoft that explains in detail how these rules work.
这篇关于web.config - 忽略特定文件夹的重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!