So, after hearing many reported outages and service issues with Webhost4life recently, I was finally hit with some downtime myself. As frustrating as it was, I’m thankful this happen 3 days before my renewal date with Webhost4life. After considering my options, I decided to move to WinHost. I needed to get it done by Monday, which was my renewal date. Well, it was much easier than I thought it would be, and so far, I really like them. Their servers definitely seem snappier, the operation is streamlined, and their control panel is very easy to use. It’s even slightly cheaper than Webhost4life.com. All and all, it was a significant upgrade in more ways than one.
One surprise with WinHost was while they support multiple domain name pointers, they don’t support auto mapping an ASP.NET application directory with a domain. In other words, while I can have many subfolders in my root web site that are each configured with IIS as separate ASP.NET applications, there is no capabilities within the WinHost control panel to associate a domain name to that subdirectory. This means, running multiple sites with separate domain names is not natively easy. Their knowledge base and forums are filled with redirect scripts – all of which end up with really ugly URL’s. In the case of my blog engine (Subtext), redirects will not work and it’s code is highly URL aware.
The good news is WinHost offers IIS 7, which has native URL rewriting capabilities at the IIS pipeline level. That means with a specially crafted Web.config sitting in my root directory, I can tap into the IIS pipeline and rewrite the URL for all incoming requests before it even reaches the ASP.NET application. I can do the same for outbound URL’s – i.e. I’m able to rewrite the base URL before ASP.NET creates a relative URL in my page. This completely solves my problem. I spent this even learning the config syntax for the IIS 7 URL Rewrite module. WinHost has this module installed on their servers, but you will need to install this locally to play with these capabilities on your local host.
Here is what my root directory looks like:
I have two subdirectories here – one for my blog (Subtext) and one for a site I host for a friend (amc_prod). Both are ASP.NET applications. The Web.config file you see there looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<!--- redirect anyone coming to kellybrownsberger.com to my blog -->
<rule name="blog-redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^www\.kellybrownsberger\.com$" />
</conditions>
<action type="Redirect" url="http://blog.kellybrownsberger.com" />
</rule>
<!-- rewrite incoming requests for my blog to the correct physical path --->
<rule name="blog-redirect-rewrite" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(blog\.)?kellybrownsberger\.com$" />
<add input="{PATH_INFO}" pattern="^/blog($|/)" negate="true" />
</conditions>
<action type="Rewrite" url="/blog/{R:0}" logRewrittenUrl="true" />
</rule>
<!-- rewrite incoming requests for AMC to the correct physical path --->
<rule name="amc-redirect-rewrite" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www\.)?myfriendsdomainname\.com$" />
<add input="{PATH_INFO}" pattern="^/amc_prod($|/)" negate="true" />
</conditions>
<action type="Rewrite" url="/amc_prod/{R:0}" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
</system.webServer>
</configuration>
This routes the incoming traffic to the correct physical paths. You’ll also need to have similar configuration in the Web.config files in your ASP.NET apps to control the outbound URLs. Here’s what the rewrite config looks like in Subtext’s Web.config file:
<system.webServer>
<rewrite>
<outboundRules>
<rule name="Outgoing - URL paths" preCondition="Not .axd files" enabled="true">
<match filterByTags="A, Form, Img, Input, Link, Script" pattern="blog(.*)" />
<conditions>
</conditions>
<action type="Rewrite" value="{R:1}" />
</rule>
<preConditions>
<preCondition name="Not .axd files">
<add input="{URL}" pattern="\.axd" negate="true" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<urlCompression doStaticCompression="false" doDynamicCompression="false" />
</system.webServer>
Hope this helps someone else out there.