簡體   English   中英

IIS7將url子文件夾重寫到父文件夾(根)

[英]IIS7 rewrite url subfolder to parent folder (root)

我有一個網站mywebsite.com,並將cms安裝到一個子文件夾中:mywebsite.com/subfolder

現在,我需要將cms移到父文件夾的根目錄,並且我希望URL可以自動重寫,因此在瀏覽mywebsite.com/subfolder/page1.php時,您將重定向到mywebsite.com/page1.php

到目前為止,我發現的唯一建議是將任何請求重定向到根文件夾。 就我而言,我需要重寫。

謝謝!

我想您的問題之所以這么老而未得到回答的原因是因為不清楚您要的是什么。 使用IIS7重寫模塊很容易,並且我將針對我認為您要問的問題提供兩個不同的示例。

因此,如果您想“重寫”子文件夾中的url,但看起來好像它們位於根目錄中,則可以使用以下命令-

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Root_URL_Rewrite" stopProcessing="true">
                    <match url="^(.*)" />
                    <action type="Rewrite" url="/subfolder/{R:0}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

但是,如果您希望重定向舊文件夾中的網址(例如,已被Google索引的網址)(作為永久301重定向),則可以使用以下示例-

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect_Root_URL" stopProcessing="true">
                    <match url="(.*)subfolder(.*)" ignoreCase="true" />
                    <action type="Redirect" url="{R:2}" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

或者,如果像我一樣,您在該頁面上絆倒了,想重寫一個子文件夾,然后執行從舊子文件夾到根目錄的永久性301重定向,則可能需要類似於以下內容的內容-

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
               <rule name="Redirect_Root_URL" stopProcessing="true">
                   <match url="(.*)subfolder(.*)" ignoreCase="true" />
                   <action type="Redirect" url="{R:2}" redirectType="Permanent" />
               </rule>
                <rule name="Root_URL_Rewrite" stopProcessing="true">
                    <match url="^(.*)" />
                    <conditions>
                        <add input="{URL}" pattern="^/subfolder/.*" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/subfolder/{R:0}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

暫無
暫無

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

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