Godaddy subdomain url rewriting

Problem:

Adding a subdomain to a hosting account with Godaddy creates a folder within the hosting root.  By default, this folder is named the same as the subdomain, but it is editable.  The issue lies within the fact that if you reference the folder, without the subdomain, you get the same site.  Therefore, navigating to blog.stevekonves.com, stevekonves.com/blog, or blog.stevekonves.com/blog all yield the same result.  The blog.stevekonves.com/blog/… address is displayed when the user navigates from the subdomain’s homepage.   This can cause issues for an MVC application which is looking for specific “folders” for routing.

Solution:

Add the following section to the site’s web.config file.

<rewrite>
  <rules>
    <rule name="Remove Virtual Directory">
      <match url=".*" />
      <action type="Rewrite" url="{R:0}" />
    </rule>
  </rules>
</rewrite>

All this does is “rewrite” the URL with itself. This causes URL Rewrite to add the original URL (the one with no folder name) to a ServerVariable which is used by ASP.NET MVC to generate other URLs.

This hack shamelessly stolen from Godaddy’s support forums: http://community.godaddy.com/groups/web-hosting/forum/topic/asp-net-mvc-routing-issue/

Posted on November 23, 2011 at 8:09 am by Steve Konves · Permalink
In: ASP.Net MVC, C#

Leave a Reply