Solved

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

Posted on 2013-02-07
13
448 Views
Last Modified: 2013-03-16
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
Comment
Question by:taz8020
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 26

Assisted Solution

by:Alan Warren
Alan Warren earned 250 total points
ID: 38865995
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
 
LVL 3

Author Comment

by:taz8020
ID: 38866062
Hi thanks I have over 300 pages, that will be a lot of code. Is there an easier way maybe in Iis?
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 38866174
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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 26

Expert Comment

by:Alan Warren
ID: 38866247
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
 
LVL 3

Author Comment

by:taz8020
ID: 38866268
Hi your a star, will try it. So does it really count in seo for the keyword to be in the page name?
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 38866299
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
 
LVL 23

Assisted Solution

by:Tony McCreath
Tony McCreath earned 250 total points
ID: 38867269
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
 
LVL 4

Expert Comment

by:Srinivasulu Muppala
ID: 38867362
<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
 
LVL 3

Author Comment

by:taz8020
ID: 38869340
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
 
LVL 23

Accepted Solution

by:
Tony McCreath earned 250 total points
ID: 38870126
<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
 
LVL 3

Author Comment

by:taz8020
ID: 38879359
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
 
LVL 3

Author Comment

by:taz8020
ID: 38904649
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
 
LVL 23

Expert Comment

by:Tony McCreath
ID: 38992654
zero points?
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
SEO can be a real minefield to navigate, but there are three simple ways to up your SEO game just be re-assessing your content output.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question