Recently I ran into an interesting situation when I was rolling out a new web-based application. I had tested it on my development server, and because it was a rather complex application I wanted to test it on my production server before making it live. I had already set up a placeholder web site with a home page that announced the new site as “Coming Soon,” and I had some of the supporting infrastructure configured for the placeholder site: database connections, permissions, FTP bindings, etc.
In order to test the new site, I could have set up a temporary web site by duplicating the placeholder web site, running my tests, and then deleting the temporary site after I was comfortable that everything was working in production. Or I could simply remove the placeholder web site and replace it with the temporary web site once the testing phase was over. I didn’t like either of those ideas, so I came up with much easier solution using URL Rewrite. Here are the details:
First, I added an additional host header binding to the placeholder web site with a temporary name that only I knew about. Since I use a wildcard A record for my DNS, I can add any additional prefixes to my domain name without registering those as CNAME records in DNS. (This makes the temporary name more difficult to discover.) For example, if I created an A record for “*.example.com,” then I could use “temp.example.com” without any changes to DNS.
Second, I added a URL Rewrite rule that checked all inbound requests by using the following logic:
- If the request was for “temp.example.com”, then URL Rewrite would allow regular access the web site.
- If the request was for any other domain name and any web page other than “ComingSoon.htm”, then URL Rewrite would redirect those requests to “/ComingSoon.htm”.
Here’s what the URL Rewrite rule looked like in my web.config file:
<rule name=”Temporary Redirect”
This allowed me to test the web site on my production server by using a temporary domain name that no one else knew about, and sending every other HTTP request to the “Coming Soon” announcement page. After a few days of putting the web site through some test passes, all that I needed to do was to remove the URL Rewrite rule and the site was officially live.