MVC C#网站+WordPress在同一目录



我有MVC C#应用程序在运行,我已经为WordPress创建了子文件夹,我正试图在同一域为WordPress文章提供服务,所以假设文章在

https://example.com/wordpress/article_title

我希望它是

https://example.com/article_title

在url 中没有WordPress的主url

我已经在WordPress网站上做了更改,但现在的主要问题是网络配置文件

我该如何为WordPress在主目录下工作编写重写规则,因为目前配置文件对WordPress URL没有任何线索,并且返回404

感谢

尝试使用以下重写规则

<rules>
<rule name="TestPattern" enabled="true" stopProcessing="true">
<match url="^[^/]+$" />
<action type="Redirect" url="wordpress/{R:0}" appendQueryString="true" />
<conditions logicalGrouping="MatchAny" />
</rule>
</rules>

案例1

这个规则将包含下面所有带有斜杠的模式,比如说,如果你的asp.net mvc应用程序路由与下面的url匹配,那么这个规则将允许这个url传递到你的mvc路由表,你的mvc页面可以被服务

  • https://example.com/controllername/actionname
  • https://example.com/abc/controllername/actionname

情况2

如果你按照你描述的方式尝试以下模式,这个规则会将你重定向到你各自的wordpress文件夹,你就可以去了

  • https://example.com/article_title

情况3

如果mvc应用程序路由表包含以下结构,那么仍然有一种方法会导致问题,那么您需要在mvc应用程序中更改路由,如actionname/controllername,或者更改wordpress重定向模式

  • https://example.com/actionanme
  • https://example.com/controllername

以下方法适用于我的

  1. 首先,我将index.php从WordPress文件夹移到man目录,并将所需的目录更改为正确的文件夹requiredir/wordpress/wp-blog-header.php
  2. 在web.config文件中添加了以下代码,以重定向所有以正斜杠结尾的URL作为WordPress页面
<rule name="WordPress: https://example.com/wordpress/" patternSyntax="WordPress">
<match url="*/"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule>

这将有助于某人,但最重要的是确保MVC网站不提供任何以正斜杠结尾的页面

最新更新