Redirecting old Sharepoint site to new location

There’s a few ways to redirect the old site to the new one, I didn’t want to involve an IIS URL rewrite so I had less options. The following seems to be the least intrusive way to get the results I wanted.

Step 1
Remove the old site on the old location. for me, I simply had to remove the content db associated with that particular site.

Step 2
Create a blank site with ability to handle 404 requests. run the following in powershell.

Add-PSSnapin "Microsoft.SharePoint.PowerShell";

$siteURL = "http://old-sharepointserver/sites/sharepoint-site";

#generate a new blank site
$template = Get-SPWebTemplate "STS#1";
New-SPSite -Url $siteURL -OwnerAlias "cpsbc\rhuie" -Template $template -SecondaryOwnerAlias "cpsbc\sp_install";

#make the 404 goto a 404 page and handle some redirect
$SPSite = Get-SPSite $siteURL;
$SPSite.FileNotFoundUrl = ($siteURL+"/404.aspx");

Step 3
create a 404.aspx file in the sharepoint site’s root

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">
    private void Page_Load(object sender, EventArgs e)
        // Check whether the browser remains
        // connected to the server.
        if (Response.IsClientConnected)
            // If still connected, redirect
            // to another page. 
            String newurl = Request.QueryString["requestUrl"];
            newurl = newurl.Replace("old-sharepointserver","new-sharepointserver");
            Response.Redirect(newurl, false);
            // If the browser is not connected
            // stop all response processing.

<html xmlns="">
    <form id="form1" runat="server">

Step 4
Rename default.aspx to default.original.aspx. We intend to do a http 302 redirect on this page. You can still access the SharePoint’s gui by accessing this file’s new name.

Step 5
Create default.aspx like the 404 file except it will just redirect to the root of the new location.

Step 6
Need to allow server code execution of 404.aspx. Otherwise you will get Code blocks are not allowed in this file.” when trying to run the files we created.
edit web.config file to include the 1 line PageParserPath below

    <SafeMode MaxControls="200" CallStack="false" DirectFileDependencies="10" TotalFileDependencies="250" AllowPageLevelTrace="false">
          <PageParserPath VirtualPath="/sites/sharepoint-site-name/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true" />