将特定的default.aspx重定向到/通过web.config

时间:2015-11-02 21:32:30

标签: c# asp.net redirect web-config

我们的网站有这样的结构:

  

http://localhost/default.aspx

     

http://localhost/aboutus/default.aspx

     

http://localhost/resources/default.aspx

     

http://localhost/mobile/default.aspx

当我将以下规则添加到web.config时,它将所有default.aspx重定向到/

    <rule name="Default Document" stopProcessing="true">
                <match url="(.*)default.aspx" />
                <action type="Redirect" url="{R:1}" redirectType="Permanent" />
            </rule>

我只想让其中两个网址重定向到/

  

http://localhost/default.aspx重定向到http://localhost/

     

http://localhost/mobile/default.aspx重定向到http://localhost/mobile/

你能帮帮忙吗?提前谢谢。

1 个答案:

答案 0 :(得分:0)

这是解决方案:

                <rule name="root homemobile" stopProcessing="true">
                    <match url="^mobile/Default.aspx" ignoreCase="true" />
                    <action type="Redirect" url="/mobile/" redirectType="Permanent" />
                </rule>
                <rule name="root home" stopProcessing="true" patternSyntax="ExactMatch">
                    <match url="Default.aspx" ignoreCase="true"  /> 
                    <action type="Redirect" url="/" redirectType="Permanent" /> 
                </rule>
相关问题