Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to 301 redirect old URLs from a JSP site to an ASP.NET site?

Posted on 2009-07-01
5
Medium Priority
?
343 Views
Last Modified: 2013-12-17
Hello:
I am migrating a website that was once hosted on an Apache/Tomcat environment running JSP. We now have it converted to C# and moved to an ASP.NET platform.

So as not to affect our SEO rankings, how do I handle the old URLs?  I can't seem to get this to work in global.asax.

For example, on the old site we have the following URL:

http://www.mysite.com/programs/program-schedule.jsp

It now points to:

http://www.mysite.com/schedules/program-schedule.aspx

I've tried looking for the request URL in the global.asax file using either Application_Start() or Application_BeginRequest(), but what happens is the 404 catches first and it just takes it to the 404 page.  I can't seem to capture what the user has entered and then perform a 301 redirect on that page.

Any ideas?  Attached is the code that DOESN'T work.
void Application_BeginRequest(Object sender, EventArgs e)
    {
        string strAbsolutePath = System.Web.HttpContext.Current.Request.Url.AbsolutePath.ToString();
        string[] aAbsolutePath = strAbsolutePath.Split('/');
 
        if (aAbsolutePath[1] != null)
        {
            switch (aAbsolutePath[1])
            {
                case "programs":
                    RedirectExternal("http://www.mysite.com/schedules/program-schedule.aspx");
                    break;
 
 
                default:
                    //do nothing
                    break;
            }
 
        }
}
 
protected void RedirectExternal(string nURL)
    {
        // Perform a 301 Redirect.
        Response.Clear();
        Response.Status = "301 Moved Permanently";
        Response.AddHeader("Location", nURL);
        Response.End();
    }

Open in new window

0
Comment
Question by:cacklebunny
[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
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 24756952
0
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 24756958
0
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 24756968
0
 
LVL 2

Author Comment

by:cacklebunny
ID: 24758258
Mohan:

Thanks for the links.  Unfortunately, these pages reflect rudimentary tutorials and explanations about what a 301 redirect is and 301 best practices, both of which I'm already familiar.  They do not address my specific issue.

Thanks again.
0
 
LVL 2

Accepted Solution

by:
cacklebunny earned 0 total points
ID: 24766555
Since no answer is forthcoming, I've researched and found an ISAPI plugin that looks like it will achieve what I want.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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