Solved

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

Posted on 2013-02-07
13
416 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 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
 
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 23

Assisted Solution

by:Tiggerito
Tiggerito 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:
Tiggerito 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:Tiggerito
ID: 38992654
zero points?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
error on the asp.net page 1 33
Runtime Error 2 27
Connection String 16 42
Not seen Link button 5 0
Wondering how you can get your new website ranking on Google Search so that people find you online?  The answer is Search Engine Optimization (SEO). So how do you Start Ranking a New site with SEO?  Below is a starter guide to get your new website S…
A/B testing is a simple and effective trick to get to know your audience, increase website conversions and make the most out of your online ad campaigns. It's widely available and doesn't need much tech knowledge to be executed, but the results it y…
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…
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.

930 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now