Url Redirect for moved blog

namespace Director
{
    public class HttpModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(this.context_BeginRequest);
        }

        private void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext context = application.Context;

            if (context.Request.FilePath.TrimEnd('/').Length > 0 
                && !File.Exists(context.Request.PhysicalPath))
            {
                context.Response.Redirect(
                    $"http://scrapbook.qujck.com{context.Request.FilePath}",
                    true);
            }
        }

        public void Dispose()
        {
        }
    }
}
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
    <add name="HttpModule" type="Director.HttpModule" />
  </modules>
</system.webServer>

Leave a Reply