Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-02-07
13
Medium Priority
?
470 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
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 26

Assisted Solution

by:Alan Warren
Alan Warren earned 750 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 750 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 750 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] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
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 tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Suggested Courses
Course of the Month12 days, 8 hours left to enroll

971 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