Solved

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

Posted on 2013-02-07
13
411 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 23

Assisted Solution

by:Tiggerito
Tiggerito earned 250 total points
Comment Utility
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
Comment Utility
<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
Comment Utility
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
Comment Utility
<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
Comment Utility
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
Comment Utility
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
Comment Utility
zero points?
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

[Part 4 of a 6 part series called SEO Basics: 5 SEO Secrets for Creating Content that Drives Traffic (http://www.experts-exchange.com/Web_Development/Internet_Marketing/Search_Engine_Optimization_SEO/A_8369-SEO-Basics-5-SEO-Secrets-for-Creating-Cont…
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…
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.

763 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

10 Experts available now in Live!

Get 1:1 Help Now