tags:

views:

153

answers:

0

I have a shared hosting account on Winhost and I have multiple domains pointed at the site root that I'm trying to operate as different sites, but with the same MVC application, thus:

  • www.domain1.com/1/products/123
  • www.domain2.com/2/products/456
  • www.domain3.com/3/products/789

The base route is therefore:

routes.MapRoute(
    "Default", // Route name
    "{siteId}/{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

I now need an IIS7 Rewrite rule to perform a redirect so that www.domain1.com ALWAYS routes to www.domain1.com/1/

Secondly, if the user types www.domain1.com/2/... I want to forcefully them back to www.domain1.com/1/....

I'm struggling to get the IIS7 rewrite to work correctly. Can anyone help with the rules for this?

On a side note, I originally wanted to rewrite rather than redirect, however, rewriting the path caused issues in MVC, because Route.GetVirtualPath returns the underlying path, rather than the rewritten one. Thus if you rewrite rather than redirect, you'll get paths such as www.domain1.com/1/1/products/123 for anything that relies on that method (paging for instance).