58BITS
  • Home
  • Tech Stuff
  • Other Stuff
  • Photos
  • About
  • Contact
58BITS
  • Home
  • Tech Stuff
  • HTTP 301 Redirect in ASP.Net for an Entire...

HTTP 301 Redirect in ASP.Net for an Entire Directory

Submitted on Feb 06, 2007, 8:44 p.m.

Having recently moved my DasBlog  tech blog from one domain to another I wanted an easy way to redirect all the traffic from the old domain, to the new one.

My shared hosting provider doesn’t provide directory level redirects (although this can be done in IIS) – only domain level.

There are also plenty of examples out there for how to redirect a single page – typically Default.aspx. What I wanted was true SEO friendly Url for Url permanent HTTP 301  redirection for every page and service in the blog.

Since the blogging engine and directory contents were the same all I needed to replace was the name portion of the domain name for the incoming Urls, redirecting them to the same resource, but on the new domain.

So I knocked to together an HTTP Handler that looks like this.

namespaceDotBits.Handlers
{
  publicclassRedirectHandler:IHttpHandler
  {
     publicvoidProcessRequest(HttpContextcontext)
     {
        context.Response.Status ="301 Moved Permanently";
       stringurl = context.Request.Url.ToString().Replace("dotbits","58bits");
        context.Response.AddHeader("Location", url);
      }

      publicboolIsReusable
     {
       get {returnfalse; }
     } 
   }
}

And then a reference to the handler with the correct path statement in the Web.config file.

<system.web>
   <httpHandlers>
     <addverb="*"path="blog/*.*"type="DotBits.Handlers.RedirectHandler"/>
   </httpHandlers>
</system.web>

Presto. Works for all registered ASP.Net resource types; .aspx, .asmx, .axd etc.

Featured

ความเสี่ยงที่เกี่ยวข้องกับเทคโนโลยีหน้าจอสำหรับเด็ก (วัยก่อนรุ่นและวัยรุ่น)

ความเสี่ยงที่เกี่ยวข้องกับเทคโนโลยีหน้าจอสำหรับเด็ก (วัยก่อนรุ่นและวัยรุ่น)

Sep 15, 2024, 10:53 a.m.
An Executive Summary of the Current State of AI

An Executive Summary of the Current State of AI

Jul 20, 2024, 5:45 p.m.
Digital Media Preservation - Why Media Organizations Can’t Archive

Digital Media Preservation - Why Media Organizations Can’t Archive

Sep 17, 2012, 11:59 a.m.
The Long Road Home

The Long Road Home

Nov 09, 2011, 8:12 p.m.

Latest

อันตรายที่ซ่อนเร้นของน้ำตาล: ผลกระทบต่อสมองเด็กและสุขภาพผู้ใหญ่

Nov 27, 2024, 2:36 a.m.

General Purpose Encrypt and Decrypt Functions with Jose

Sep 16, 2024, 11:19 p.m.

ความเสี่ยงที่เกี่ยวข้องกับเทคโนโลยีหน้าจอสำหรับเด็ก (วัยก่อนรุ่นและวัยรุ่น)

Sep 15, 2024, 10:53 a.m.

Migrating a Google Workspace Account to a Personal Google Gmail Account

Aug 04, 2024, 9:30 p.m.
58bits

Tech, art, and life...

Copyright © 2026 Anthony Bouch. All rights reserved.

Made with ❤️ by Infonomic

Explore
  • Home
  • Tech Stuff
  • Other Stuff
  • Photos
Legal
  • Terms of Use
  • Privacy Policy
  • Cookies
Connect
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Copyright © 2026 Anthony Bouch. All rights reserved.

Made with ❤️ by Infonomic

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.