Routing Classic ASP Requests To .NET - SEO Redirects

后端 未结 4 1638
梦如初夏
梦如初夏 2021-01-06 05:18

We are replacing an old classic asp website with a .NET 3.5 solution.

We need to redirect all of the classic ASP requests to aspx pages (i.e. contactus.asp, may now

相关标签:
4条回答
  • 2021-01-06 05:26

    I use a modified version of the Smart 404 Handler script from http://evolvedcode.net/content/code_smart404/. I added code to do custom mapping based of a table in our database.

    This script could easily be re-written in ASP.NET and then mapped the same way.

    0 讨论(0)
  • 2021-01-06 05:30

    Big edit: I was pointed by @EdSF in the comments that the answer was wrong. In disbelief I checked using Firebug, and, in fact, it was wrong.

    You need to use Context.Response.RedirectLocation for the status code to work.

    enter image description here


    I'm doing the same in global.asax:

    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim fullOriginalpath As String = Request.Url.ToString.ToLower
    
        If (fullOriginalpath.Contains("/verarticulo.asp?articuloid=")) Then
            Context.Response.StatusCode = 301
            ''// this does not work, returns a 302
            ''//Context.Response.Redirect("/noticias/" + getIDFromPath(fullOriginalpath))
    
            ''// this does right way
            Context.Response.RedirectLocation = "/noticias/" + getIDFromPath(fullOriginalpath)
            Context.Response.End()
        ElseIf (fullOriginalpath.Contains("/archivo.asp")) Then
            Context.Response.StatusCode = 301
            Context.Response.RedirectLocation = "/archivo/" 
            Context.Response.End()
        ElseIf (fullOriginalpath.EndsWith("/default.asp")) Then
            Context.Response.StatusCode = 301
            Context.Response.RedirectLocation = "/"
            Context.Response.End()
        End If
    End Sub
    

    The only thing you have to do if you are using II6 you have to configure this ISAPI filter in this way:

    enter image description here

    The file is c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll

    0 讨论(0)
  • 2021-01-06 05:35

    Eduardo Molteni's answer works, except for one thing. It actually passes the browser a 302 instead of a 301.

    I believe instead of:

    Context.Response.StatusCode = 301 
    Context.Response.Redirect("/something/") 
    

    it should be:

    Context.Response.StatusCode = 301 
    Context.Response.RedirectLocation = "/something") 
    

    The response.redirect is basically interrupting what you were setting up with the Response.StatusCode and the browser ends up getting a "302 Found".

    I'm not really sure how search engines handle a 302 vs a 301 so maybe its not an issue. It seems to me though that a true Permanent Redirect (301) would be preferred.

    For those on v4 of the framework, there seems to be a new option:

    Response.RedirectPermanent("/something")
    

    I haven't tested this, but I'm assuming it provides a 301 as the status code. Details here: HttpResponse.RedirectPermanent

    0 讨论(0)
  • 2021-01-06 05:39

    The simplest thing is to use a custom 404 error page at the IIS level. This page can be any ASPX page; you have access to the original request via the HttpContext.

    In IIS 6.0, you'll notice that by default URLs mapped to the .NET engine (.aspx,,asmx etc) use their own 404 handler defined in web.config. No matter; you can cause even those pages to be sent to the IIS 404 page if you edit the ASPX engine mapping and ensure that the tickbox for "file must exist" is set. This redirects all boken links to the IIS 404 handler, even if they are mapped to .NET handlers. People make the mistake of trying to redirect all broken links to the web.config defined 404handler; it's must easier if you just force all to go to the IIS defined one instread.

    0 讨论(0)
提交回复
热议问题