【问题标题】:Redirect all older URL ending with .aspx to some URL将所有以 .aspx 结尾的旧 URL 重定向到某个 URL
【发布时间】:2014-04-01 07:13:32
【问题描述】:

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

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

我想使用重写模块。

【问题讨论】:

标签: asp.net redirect


【解决方案1】:

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

安装后,将以下部分添加到 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 URL 重定向到某个域,您可以将操作更改为:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-23
    • 2011-10-11
    • 1970-01-01
    • 2018-05-07
    • 1970-01-01
    • 2014-05-13
    • 1970-01-01
    • 2017-08-17
    相关资源
    最近更新 更多