MVC3 + WordPress IIS Url Rewriting Rules

前端 未结 3 1800
别跟我提以往
别跟我提以往 2021-01-06 23:11

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 p

相关标签:
3条回答
  • 2021-01-06 23:41

    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?!?!

    0 讨论(0)
  • 2021-01-06 23:42

    I had a similar situation but I had no need to edit my web.config file. Instead I followed instructions here at https://wordpress.org/support/article/giving-wordpress-its-own-directory/ where this is documented.

    At point 7) within Moving WordPress process to a subfolder Method II (With URL change) you find options for a IIS installation.

    0 讨论(0)
  • 2021-01-07 00:03

    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>
    
    0 讨论(0)
提交回复
热议问题