簡體   English   中英

MVC3 + WordPress IIS Url 重寫規則

[英]MVC3 + WordPress IIS Url Rewriting Rules

我有一個位於http://mydomain.com/mymvcapp/的 ASP.NET MVC3 網站。 但是,網站 (mydomain.com) 的根目錄包含一個運行 PHP 的 WordPress 站點。 因此,我設置了以下 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>

因此,有了這條規則,我的 WordPress 就可以完美運行,但是,我的 MVC 重寫不起作用。 我將如何更改此規則以允許 WordPress 和 MVC(在 /mymvcapp/ 文件夾下)很好地共存?

我自己想出來的。 Regex 可能是迄今為止最強大的復雜/令人困惑的技術之一。 但在這種情況下,patternSyntax 標志設置為 Wildcard,而不是 Regex,這讓我感到困惑。 希望這可以幫助其他人! =]

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

這是極少數討論如何使 WordPress 和 ASP.NET 在 IIS 設置中良好共存的帖子之一。 因此,為此感到榮幸。

我想將此作為對您的原始問題或答案的評論發布,但我選擇寫一個“答案”只是因為這是一個誠實的問題並且我需要一些格式化功能。

我有多個按站點運行的 ASP.NET 應用程序。 特別是根網站正在運行 MVC4 應用程序。

由於我不能在根目錄下安裝 WordPress,我的計划是將它放在自己的應用程序文件夾http://mydomain.com/wordpress/上,然后有一個 URL 重寫規則來執行以下操作(使用偽代碼) :

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

我只是用這種方法造成了混亂,並且沒有成功使用漂亮的永久鏈接,有時會進入重定向循環,有時會破壞指向 .css 文件、管理頁面等的鏈接……

你有沒有想過這個,即,將 wordpress 作為一個子應用程序,並進行子域 URL 重寫???!

我有類似的情況,但我不需要編輯我的 web.config 文件。 相反,我遵循了https://wordpress.org/support/article/giving-wordpress-its-own-directory/上的說明,其中記錄了這一點。

在第 7 點),在將 WordPress 進程移動到子文件夾方法 II(使用 URL 更改)中,您可以找到 IIS 安裝選項。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM