且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

IIS7 URL 从根目录重定向到子目录

更新时间:2023-09-04 18:47:28

就在这里.将此代码添加到您的 web.config 文件:

Here it is. Add this code to your web.config file:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="Root Hit Redirect" stopProcessing="true">
                <match url="^$" />
                <action type="Redirect" url="/menu_1/MainScreen.aspx" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

它将执行 301 永久重定向(URL 将在浏览器中更改).如果你想让这样的重定向"不可见(重写,内部重定向),那么使用这个规则(唯一的区别是重定向"已经被重写"代替了):

It will do 301 Permanent Redirect (URL will be changed in browser). If you want to have such "redirect" to be invisible (rewrite, internal redirect), then use this rule (the only difference is that "Redirect" has been replaced by "Rewrite"):

<system.webServer>
    <rewrite>
        <rules>
            <rule name="Root Hit Redirect" stopProcessing="true">
                <match url="^$" />
                <action type="Rewrite" url="/menu_1/MainScreen.aspx" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>