I wrote this PHP site that I wanted to move over to a new domain.
Originally, I had just planned on rewriting the site in ASP.NET, but since webhost4life.com offers PHP hosting as well, I just put the existing site on the new domain until I have time to finish the new version.
The only catch is that, as I was already asking people to update their links, I didn't want them to have to update again once I finished the ASP.NET version.
I decided to write a simple HttpModule that would map the requests to the existing PHP pages. Then when I'm done developing the ASP.NET site, I can just remove the module from my web.config and all is well. The key point here is that the browser's url doesn't change - so I don't have to worry about someone bookmarking the 'old' site.
Response.Redirect changes the browser's url, which defeats the whole purpose of this exercise. Server.Execute and Server.Transfer wouldn't work, because it's not an ASPX page I'm going to.
What I wanted to do was something similar to the way HttpContext.RewritePath behaves. The problem with using RewritePath, of course, is that the HTTP request has already been mapped to ASP.NET, which knows nothing about PHP. So when I call RewritePath('default.php'), it's going to return the PHP page as is - without interpreting the commands inside.
My solution was to use HttpWebRequest. So when you come in and ask for default.aspx, I'm actually creating a new web request for default.php. I take the output from that (generated by the PHP engine) and dump it into the Response stream. You and your browser still think you're on default.aspx, and no one realizes that I'm actually using PHP under the hoods!
Obviously this has some performance implications, but I'm doing my best to mitigate them by caching the responses. The site has a lot of complicated and fairly expensive database calls, so this could actually improve performance considerably, despite the “double dip” request. Plus, it's only a very short-term solution!
By the way, I would prefer to have URLs that were not technology specific, but I wouldn't be able to do this with shared hosting unless the extension is already mapped to the ASN.NET ISAPI. I've asked, but I'm guessing that I can't change this.
