I just changed the domain of my site and I wanted to create a page notifying that the site has moved and then auto redirect them after a few seconds. Here’s how I did it:
1) I’m using IIS 7.5 so I opted to use the IIS7 RewriteModule. I simply ran the installer and the applet appears under the site options.
2) I created a catch all site in IIS and bound it to all the old public domains:
3) Then created a UrlRewrite Rule to rewrite all requests to /Default.aspx (Except ones specifically to /Default.aspx):
4) Next created the redirection page (Stripped down for clarity):
<%@ Page Language="C#" %>
<%
string redirectUrl = string.Format("{0}://{1}{2}{3}",
Request.Url.Scheme,
Request.Url.Host.Replace("mikeobrien.net", "mikeobrien.net"),
(Request.Url.Port != 80 ? ":" + Request.Url.Port : string.Empty),
Request.Headers["X-Original-URL"]);
%>
<html>
<head>
<title>We've Moved</title>
<script language="javascript">
function RedirectPage(url, seconds)
{
self.setTimeout('self.location.href = \'' + url + '\';', seconds * 1000);
}
function CountDown(seconds, elementId)
{
if (seconds == 0) return;
document.getElementById(elementId).innerHTML = seconds;
self.setTimeout('CountDown(' + (seconds - 1) + ', \'' + elementId + '\');', 1000);
}
</script>
</head>
<body onLoad="RedirectPage('<% = redirectUrl %>', 5);CountDown(5, 'timeLeft');">
<h3>We've moved!</h3>
<p>
The page you requested can now be found <a href="<% = redirectUrl %>">here</a>.
You will be redirected in <span id="timeLeft">5</span> seconds.
</p>
</body>
</html>
5) And voila!
