将以.aspx结尾的所有旧网址重定向到某个网址

时间:2014-04-01 07:13:32

标签: asp.net redirect

我已将网站升级为更新的asp.net mvc版本。它已经完成,但我不知道如何将以aspx结尾的旧页面请求重定向到新的URL。

如何将以.aspx结尾的所有网页请求重定向到主页网址,例如www.somedomain.com /

我想使用重写模块。

1 个答案:

答案 0 :(得分:9)

要使用重写模块将aspx结尾的所有内容重定向到扩展名较少的URL,您必须首先安装URL重写模块。最好是使用Web Platform Installer

安装URL重写模块

安装完成后,将以下部分添加到< system.webServer> web.config中的部分:

<rewrite>
    <rules>
        <rule name="Redirect to extensionless URL" patternSyntax="Wildcard" stopProcessing="true">
            <match url="*.aspx" />
            <action type="Redirect" url="{R:1}" redirectType="Found" />
        </rule>
    </rules>
</rewrite>

此部分定义任何与模式* .aspx匹配的URL将被重定向(302)到扩展名较少的URL等效项。例如,对/Users.aspx的请求将被重定向到/Users

如果您想将所有.aspx网址重定向到某个域,您可以将操作更改为:

<action type="Redirect" url="http://www.somedomain.com" redirectType="Found" />

从SEO的角度来看,302重定向并不理想,因此我建议使用302重定向测试,如果一切正常,请使用操作切换到永久重定向:

<action type="Redirect" url="{R:1}" redirectType="Permanent" />
相关问题