Back in May of this year I wrote a blog entry on my first year of hosting ScottOnWriting.NET and other assorted sites with WebHost4Life. One of the pros of WebHost4Life that I mentioned in the review is that you could host multiple Web sites on one account, using one of two options:
- Paying $15/year to have a domain name map to a specific directory.
- Paying nothing, and having the default.aspx page in your site check the URL and redirect the request to the appropriate subdirectory.
The first approach is definitely more professional, as a request to www.somesite.com will remain as www.somesite.com in the user's browser, and not require an extra request to the Web server. With the second approach, however, when a user visits www.somesite.com, they'll be redirected to some other subdirectory on the site, like www.somesite.com/ss. I use this approach here on my blog (note that if you visit www.ScottOnWriting.NET you get auto-redirected to www.ScottOnWriting.NET/sowBlog).
Anywho, a poster named Chris had the following question:
Excuse me for being completely new to ASP.NET, but in I was wondering if you could point me to a tutorial on the "hosting multiple sites using default.aspx" method? I'd like to try this as I can't justify $15 per domain. Thanks!
Chris, here is the code I use in the root Web directory's default.aspx page to redirect the user to the appropriate subdirectory based on their URL (this code would go in the Page_Load event handler):
If Request.Url.Host.ToUpper().IndexOf("SCOTTONWRITING.NET") >= 0 then
Response.Redirect("/sowBlog/")
Response.End()
ElseIf Request.Url.Host.ToUpper().IndexOf("SKMMENU.COM") >= 0 then
Response.Redirect("/menu/")
Response.End()
ElseIf Request.Url.Host.ToUpper().IndexOf("NBAWEBLOG.COM") >= 0 then
Response.Redirect("/nba/")
Response.End()
End If
As you can see, there are three URLs that will redirect the visitor to a specific subdirectory: ScottOnWriting.NET, skmMenu.com, and NBAWebLog.com. This approach is used to host these hobby/personal sites all on one WebHost4Life account without having to shell out the extra $15/year for the Web server-level mapping of domain name to subdirectory.
Hope this helps, Chris!