简体   繁体   English

MVC3 + WordPress IIS Url 重写规则

[英]MVC3 + WordPress IIS Url Rewriting Rules

I have a ASP.NET MVC3 website located at http://mydomain.com/mymvcapp/ .我有一个位于http://mydomain.com/mymvcapp/的 ASP.NET MVC3 网站。 However, the root of the webiste (mydomain.com) contains a WordPress site running PHP.但是,网站 (mydomain.com) 的根目录包含一个运行 PHP 的 WordPress 站点。 Therefore, I put the following IIS URL Rewrite rule to allow WordPress to function correctly via its rewriting mechanisms:因此,我设置了以下 IIS URL 重写规则,以允许 WordPress 通过其重写机制正常运行:

    <rewrite>
        <rules>
            <rule name="wordpress" patternSyntax="Wildcard">
                <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>     
        </rules>
    </rewrite>

So with this rule in place my WordPress functions perfectly, however, my MVC rewriting does NOT work.因此,有了这条规则,我的 WordPress 就可以完美运行,但是,我的 MVC 重写不起作用。 How would I alter this rule to allow both WordPress and MVC (under the /mymvcapp/ folder) to coexist nicely?我将如何更改此规则以允许 WordPress 和 MVC(在 /mymvcapp/ 文件夹下)很好地共存?

Figured it out on my own.我自己想出来的。 Regex is probably one of the most powerful YET complicated / confusing technologies there is. Regex 可能是迄今为止最强大的复杂/令人困惑的技术之一。 But in this case the patternSyntax flag was set to Wildcard, not Regex, which caused my confusion.但在这种情况下,patternSyntax 标志设置为 Wildcard,而不是 Regex,这让我感到困惑。 Hope this helps someone else out there!希望这可以帮助其他人! =] =]

    <rewrite>
        <rules>
            <rule name="wordpress" patternSyntax="Wildcard">
                <match url="*" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{PATH_INFO}" pattern="/mymvcapp/*" 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>     
        </rules>
    </rewrite>

This is one of the very few posts anywhere that talks about making WordPress and ASP.NET coexist nicely in an IIS setup.这是极少数讨论如何使 WordPress 和 ASP.NET 在 IIS 设置中良好共存的帖子之一。 So Kudos for that.因此,为此感到荣幸。

I was thinking to post this as comment to either your original question or the answer, but I chose to write an "answer" only because this is an honest question and I need some formatting capabilities.我想将此作为对您的原始问题或答案的评论发布,但我选择写一个“答案”只是因为这是一个诚实的问题并且我需要一些格式化功能。

I have multiple ASP.NET apps running on by site.我有多个按站点运行的 ASP.NET 应用程序。 In particular the root website is running an MVC4 app.特别是根网站正在运行 MVC4 应用程序。

Since I cannot have WordPress installed at the root, my plan was to have it on its own app folder http://mydomain.com/wordpress/ and then have a URL-rewrite rule that to do the following (using peudo-code):由于我不能在根目录下安装 WordPress,我的计划是将它放在自己的应用程序文件夹http://mydomain.com/wordpress/上,然后有一个 URL 重写规则来执行以下操作(使用伪代码) :

blog.mydomain.com/{path} --> mydomain.com/wordpress/{path}

I've only caused a mess with this approach and have not been successful using pretty permalinks, sometimes getting into redirect-loops and other times breaking links to.css files, admin pages, etc...我只是用这种方法造成了混乱,并且没有成功使用漂亮的永久链接,有时会进入重定向循环,有时会破坏指向 .css 文件、管理页面等的链接……

Have you ever given this a thought, ie, having wordpress as a subapp instead and do sub-domain URL-rewriting???!你有没有想过这个,即,将 wordpress 作为一个子应用程序,并进行子域 URL 重写???!

I had a similar situation but I had no need to edit my web.config file.我有类似的情况,但我不需要编辑我的 web.config 文件。 Instead I followed instructions here at https://wordpress.org/support/article/giving-wordpress-its-own-directory/ where this is documented.相反,我遵循了https://wordpress.org/support/article/giving-wordpress-its-own-directory/上的说明,其中记录了这一点。

At point 7) within Moving WordPress process to a subfolder Method II (With URL change) you find options for a IIS installation.在第 7 点),在将 WordPress 进程移动到子文件夹方法 II(使用 URL 更改)中,您可以找到 IIS 安装选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM