Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 490
  • Last Modified:

asp.net redirect all old urls to new url Like in .htaccess for unix

1). Hi I have built a new site in asp.net and almost ready to launch it. Only promlem is So i dont loose all the seo work done on the old site, i want 301 permanent redirect like i used to do in the .htaccess file.

Old names on old unix server ere like www.site.com/clothing.html on the new asp.net site they will all be like www.site.com/sections/0.aspx

so www.site.com/clothing.html  goes to www.site.com/sections/0.aspx

2). PS do you think its best to use www.site.com/sections/0.aspx or www.site.com/sections/clothing.aspx, I chose to use the section index so its easier to rename if needed. but if it would effect seo then will use the other.
0
taz8020
Asked:
taz8020
  • 5
  • 4
  • 3
  • +1
3 Solutions
 
Alan WarrenApplications DeveloperCommented:
If your page is about clothing, from an SEO perspective I'd be inclined to keep the keyword clothing in the path. Anyhow that's your call, here's the script to redirect, which I would put somewhere in the masterpage code behind, possibly the page_init event.
        Dim url As String = context.Request.Url.ToString().ToLower()

        ' decode the url
        url = System.Web.HttpUtility.UrlDecode(url)

        ' Redirect "/clothing.html" to root + sections/0.aspx
        If InStr(url, "/clothing.html", CompareMethod.Text) > 0 Then
            context.Response.StatusCode = 301
            context.Response.StatusDescription = "Moved Permanently"
            context.Response.AddHeader("Location", "~/sections/0.aspx")
        End If

Open in new window

Alan
0
 
taz8020Author Commented:
Hi thanks I have over 300 pages, that will be a lot of code. Is there an easier way maybe in Iis?
0
 
Alan WarrenApplications DeveloperCommented:
Might be able to use a  select case block.
Even using UrlReWrite in IIS you will still need to define the re-writes.
        Dim strRedirect As String = ""
        Select Case url
            Case InStr(url, "/clothing.html", CompareMethod.Text) > 0
                strRedirect = "~/sections/0.aspx"
            Case InStr(url, "/bedding.html", CompareMethod.Text) > 0
                strRedirect = "~/sections/1.aspx"
            Case InStr(url, "/linen.html", CompareMethod.Text) > 0
                strRedirect = "~/sections/2.aspx"
        End Select

        context.Response.StatusCode = 301
        context.Response.StatusDescription = "Moved Permanently"
        context.Response.AddHeader("Location", strRedirect)

Open in new window

Alan
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Alan WarrenApplications DeveloperCommented:
Apologies, logic error in my last post, the redirect will always fire, even when not needed:
       Dim strRedirect As String = ""
        Dim bolRedirect As Boolean = False
        Select Case url
            Case InStr(url, "/clothing.html", CompareMethod.Text) > 0
                strRedirect = "~/sections/0.aspx"
                bolRedirect = True
            Case InStr(url, "/bedding.html", CompareMethod.Text) > 0
                strRedirect = "~/sections/1.aspx"
                bolRedirect = True
            Case InStr(url, "/linen.html", CompareMethod.Text) > 0
                strRedirect = "~/sections/2.aspx"
                bolRedirect = True
        End Select

        If bolRedirect = True Then
            context.Response.StatusCode = 301
            context.Response.StatusDescription = "Moved Permanently"
            context.Response.AddHeader("Location", strRedirect)

        End If

Open in new window

Alan
0
 
taz8020Author Commented:
Hi your a star, will try it. So does it really count in seo for the keyword to be in the page name?
0
 
Alan WarrenApplications DeveloperCommented:
Yes I believe it does, though read a few articles about exact match domain name, which apparently counts against you now, Exact Match Domain Penalty Added to Google Algo

Gofigure!
0
 
Tony McCreathTechnical SEO ConsultantCommented:
With the latest.Net you can do a 301 redirect in one line:

this.Response.RedirectPermanent("http://www.website.com/new-page/");

Open in new window

                   

It also supports a similar concept to .htaccess via the web.config file. Here you can use regex to redirect whole sets of pages in one go.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="301 Redirect 1" stopProcessing="true">
          <match url="^old-page\.htm$" />
          <action type="Redirect" url="new-page" redirectType="Permanent" />
        </rule>
        <rule name="301 Redirect 2" stopProcessing="true">
          <match url="^old-page2\.htm$" />
          <action type="Redirect" url="new-page2" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration> 

Open in new window


Keywords in the URL page can add a little more of a signal to the search engines about the primary subject of a page.

The EMD (Exact Match Domain) Algo that came out a few months ago is targeting poor quality websites using keywords in the domain name. If your content is good you don't need to worry, but you may not get as big a benefit for having an EMD as you did in the past.
0
 
Srinivasulu MuppalaLead DeveloperCommented:
<urlMappings enabled="true" >

       <!--url which you want mappedURL = transfered url location -->

      <add mappedUrl="~/Detail.aspx?id=1" url="~/one.aspx"/>

      <add mappedUrl="~/Detail.aspx?id=2" url="~/two.aspx"/>

      <add mappedUrl="~/Detail.aspx?id=3" url="~/three.aspx"/>

      <add mappedUrl="~/Detail.aspx?id=4" url="~/four.aspx"/>

</urlMappings>
0
 
taz8020Author Commented:
Hi Tiggerito thanks but I have already tried your solution and did not work. It does not recognise rewrite. I am on framework 4 as my host provider does not support 4.5. Does it only work on 4.5?

Hi srinipro just tried yours and does not recognise urlMappings, wher in the web.config sould i place it and does it work on version 4?
0
 
Tony McCreathTechnical SEO ConsultantCommented:
<rewrite> was introduced in .Net 3.5 + IIS7 so you should be ok. You probably have to install and enable the Routing Module for it to work. More details:

http://www.iis.net/learn/extensions/url-rewrite-module/iis-url-rewriting-and-aspnet-routing

I think the <urlMappings> suggestion from @srinipro requires an external program to be installed.
0
 
taz8020Author Commented:
Ok got the rewite working but now want to put them in an external file as there is loads

<system.webServer>
  <rewrite>
    <rewriteMaps configSource="rewritemaps.config" />
  </rewrite>
</system.webServer>

Problem is the configSource says it is not declared any ideas
0
 
taz8020Author Commented:
Ok got the rewite working but now want to put them in an external file as there is loads

<system.webServer>
  <rewrite>
    <rewriteMaps configSource="rewritemaps.config" />
  </rewrite>
</system.webServer>

Problem is the configSource says it is not declared any ideas, plus when testing set up redirect and then canceled it, but know it still works on my one computer why and how do i fix it???
0
 
Tony McCreathTechnical SEO ConsultantCommented:
zero points?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now