views:

128

answers:

1

Hi, I am trying to redirect my old typepad blog to my new blog (permanent 301 redirect) that runs with wordpress. The new blog will also be on a new server.

the old Blog had the following structure: http://subdomain.domain.com/weblog/year/month/what-ever-article.html

The new Blog looks like this: http://www.domain.com/Blog/index.php/year/month/what-ever-article.html

I am using an http handler that I found online and tried to work with it:

    public class MyHttpModule :IHttpModule 
{ 


public MyHttpModule() 
    { 
        // 
        // TODO: Add constructor logic here 
        // 
    } 
#region IHttpModule Members 

public void Dispose() 
{ 

} 

public void Init(HttpApplication context) 
{ 
    context.BeginRequest += new EventHandler(context_BeginRequest); 
} 

void context_BeginRequest(object sender, EventArgs e) 
{
    string oldURL = System.Web.HttpContext.Current.Request.Url.ToString();
    string newURL = String.Empty;
    //oldURL = 

    if (oldURL.ToString().ToLower().IndexOf("articles") >= 0 || System.Web.HttpContext.Current.Request.Url.ToString().ToLower().IndexOf("weblog") >= 0)
    {
        newURL = oldURL.Replace("subdomain.domain.com/weblog", "www.domain.com/Blog/index.php");
        if (newURL.ToLower().Contains("subdomain"))
        {
            newURL = "http://www.domain.com/Blog";
        }
    }
    else
    {
        newURL = "http://www.domain.com/Blog";
    }
    System.Web.HttpContext.Current.Response.Clear();
    System.Web.HttpContext.Current.Response.StatusCode = 301;
    System.Web.HttpContext.Current.Response.AddHeader("Location", newURL);
    System.Web.HttpContext.Current.Response.End();
} 
#endregion 

}

To use this code, I put the handler into the web.config

        <httpModules>
        <add name="MyHttpModule" type="MyHttpModule, App_Code"/>
    </httpModules>

The issue that I have is that when I want to redirect from the http://subdomain.domain.com/weblog/year/month/what-ever-article.html, I get an error that the folder would not exist.

Is there any way to change my script or add an catch all to the web.config that forwards the URL to my script?

When I use "http://subdomain.domain.com/weblog/year/month/what-ever-article.html" in oldURL string, then the redirect works just fine... so I must have some IIS or web.config settings wrong.

Thanks in advance, Patrick

+1  A: 

I think that you need to add handlers for the html page, so they can run under the asp.net

You can use the httpHandlers on web.config to add the html, or iis to handle your html or other files via the asp.net and can pass from your filter.

Aristos