将站点中的所有扩展名从 .htm 更改为 .aspx 时,这是否有效?

发布于 2024-12-27 16:55:58 字数 1156 浏览 0 评论 0原文

我的任务是对我公司的网站(约 40 页)进行改版。原始站点是直接用 html/css/javascript 编写的,每个文件都有 .htm 扩展名。新站点是用.net 3.5编写的,通过iis托管在windows上。

我根本不会更改目录结构,但每个页面都会从 .htm 扩展名变为 .aspx,我担心这将如何影响我的 SEO。

另一个 SO 问题 我找到了这篇文章的链接,详细介绍了自定义 http 模块,其中我有以下代码:

public class PermanentRedirectHttpModule : IHttpModule
{

    public void Dispose()
    {
    }

    public void Init(HttpApplication context)
    {
        context.BeginRequest += new EventHandler(context_BeginRequest);
    }

    void context_BeginRequest(object sender, EventArgs e)
    {           
        HttpContext context = HttpContext.Current;
        HttpRequest request = context.Request;

        if (request.Url.PathAndQuery.Contains(".htm"))
        {
            string url = request.Url.ToString();
            url = url.Replace(".htm", ".aspx"); 
            context.Response.Status="301 Moved Permanently";
            context.Response.AddHeader("Location", url);
            context.Response.End(); 
        } 
    } 
}

我已经实现了这个方法,一切都按照我的预期进行。这种方法可以接受吗?它会维持我的搜索引擎排名吗?

I have been tasked with giving my company's website (~40 pages) a facelift. The original site is written in straight html/css/javascript and every file has the .htm extension. The new site is written in .net 3.5, Hosted on windows through iis.

I am not changing the directoy structure at all, but every page will go from a .htm extension to .aspx and I am concerned about how this will effect my SEO.

From another SO question I found a link to this article detailing a custom http module from which I have the following code:

public class PermanentRedirectHttpModule : IHttpModule
{

    public void Dispose()
    {
    }

    public void Init(HttpApplication context)
    {
        context.BeginRequest += new EventHandler(context_BeginRequest);
    }

    void context_BeginRequest(object sender, EventArgs e)
    {           
        HttpContext context = HttpContext.Current;
        HttpRequest request = context.Request;

        if (request.Url.PathAndQuery.Contains(".htm"))
        {
            string url = request.Url.ToString();
            url = url.Replace(".htm", ".aspx"); 
            context.Response.Status="301 Moved Permanently";
            context.Response.AddHeader("Location", url);
            context.Response.End(); 
        } 
    } 
}

I have implemented this method and everything works as I would expect it to. Is this method acceptable and will it maintain my search engine rankings?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倚栏听风 2025-01-03 16:55:58

这可以通过将所有 .htm 路径重定向到 .aspx 来实现。由于您正在进行 301 重定向,因此您可能会注意到随着权力转移,搜索引擎排名会暂时下降。您还需要确保网站上的所有链接都转到新 URL,否则您将收到大量内部 301 重定向。

另一种方法是使用 URL 重写。通过这种方式,您可以维护 .htm URL,但它们将被重写以指向 .aspx 页面。

Helicon ISAPI (http://www.isapirewrite.com/) 是我经常使用的一个。如果您的服务器上只有 1 个站点,则可以使用精简版(免费)。

如果您使用的是 IIS7,则可以使用在站点的 web.config 文件中配置的内置重写。

This would work by redirecting all of your .htm paths to .aspx. Because you're doing a 301 redirect, you might notice a temporary drop in search engine places as the power gets transferred. You'll also need to make sure that any links on your site go to the new URLs, otherwise you'll get alot of internal 301 redirects.

An alternative would be to use URL rewriting. This way you could maintain your .htm URLs, but they would be rewritten to point to the .aspx pages.

Helicon ISAPI (http://www.isapirewrite.com/) is one I often use. If you just have the 1 site on the server, you can get away with using the lite (free) version.

If you're using IIS7, you could use the built in rewrites which are configured in the web.config file of your site.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文