MVC3 + WordPress IIS Url Rewriting Rules

寵の児 提交于 2019-12-19 04:09:21

问题


I have a ASP.NET MVC3 website located at http://mydomain.com/mymvcapp/. However, the root of the webiste (mydomain.com) contains a WordPress site running PHP. Therefore, I put the following IIS URL Rewrite rule to allow WordPress to function correctly via its rewriting mechanisms:

    <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. How would I alter this rule to allow both WordPress and MVC (under the /mymvcapp/ folder) to coexist nicely?


回答1:


Figured it out on my own. Regex is probably one of the most powerful YET complicated / confusing technologies there is. But in this case the patternSyntax flag was set to Wildcard, not Regex, which caused my confusion. 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>



回答2:


This is one of the very few posts anywhere that talks about making WordPress and ASP.NET coexist nicely in an IIS setup. 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. In particular the root website is running an MVC4 app.

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):

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...

Have you ever given this a thought, i.e., having wordpress as a subapp instead and do sub-domain URL-rewriting?!?!



来源:https://stackoverflow.com/questions/11068932/mvc3-wordpress-iis-url-rewriting-rules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!