The first thing that struck me was that Winhost.com don't allow you to host multiple domains (or sub domains) as individual websites under one account. Essentially you have one IIS7 Website per account. This is something you can do on Webhost4life.com, and was one of the main reasons I went with them in the first place. I'm a web application developer, which means I want to be able to run numerous websites under one hosting account. It seems that this is a challenge to get for free in a Windows hosting environment.
My aim is to do the following (S: is the account root path):
- http://www.mydomain.com/ => S:\MyRoot\Main
- http://sub1.mydomain.com/ => S:\MyRoot\Sub1
- http://sub2.mydomain.com/ => s:\MyRoot\Sub2
What I don't want (which is what Winhost.com suggest) is to end up with:
- http://www.mydomain.com/main/default.aspx
- http://sub1.mydomain.com/sub1/default.aspx
- http://sub2.mydomain.com/sub2/default.aspx
Because, face it, that looks like shit.
So, we'll turn to IIS7's Url Rewrite feature to get this working. First of all configure your "Application Starting Points" from your Winhost.com Site Manager. You'll need four of them:
- /
- /Main
- /Sub1
- /Sub2
Now login via FTP and create a new web.config file in the root ("/") directory. Paste the following code in:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<rewrite>
<rules>
<rule name="Rewrite to folder1" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.mydomain.com$" />
</conditions>
<action type="Rewrite" url="main/{R:1}" />
</rule>
<rule name="Rewrite to folder2" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^sub1.mydomain.com$" />
</conditions>
<action type="Rewrite" url="sub1/{R:1}" />
</rule>
<rule name="Rewrite to folder3" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^sub2.mydomain.com$" />
</conditions>
<action type="Rewrite" url="sub2/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
You can remove any other files from the root folder (i.e. "/").
This should also work on DiscountASP.net, as they appear to have a very similar set up.

22 comments: