Alan Jackson
Alan Jackson

Reputation: 6511

How do I keep subdomain.domain.com links from mapping to subdomain.domain.com/subdomain?

I have a virtual directory created and a sub domain that points to that virtual directory. My links always route to subdomain.domain.com/subdomain/controller/action when they can leave off the subdomain link. Is there an easy way to stop that?

Also, it's the same problem when I mapped anotherdomain.com to my virtual directory. It ends up linking to anotherdomain.com/virtualdir/controller/action.

It just looks unprofessional to me to have all my links be myapp.com/myapp/action/controller.

Upvotes: 1

Views: 359

Answers (1)

Dan Atkinson
Dan Atkinson

Reputation: 11699

I have also wondered this, but I don't believe that you can achieve this in the ready-made routing that comes with ASP.NET MVC.

Thankfully, the user has a great deal of freedom in choosing how they want to handle these things, and a solution that you may want to consider can be found here.

The ASP.NET MVC team appear to have recognised that this should be pre-baked into MVC by default, but I don't see anything being done about until v2 as it will require changes to the routing engine.

Failing this, you may want to consider url rewrites (this is obviously much easier if you have IIS7). Here is an IIS forum post discussing this.

IIS 7 Rewrite Example (taken from here):

<rule name="RewriteSubdomain">
  <match url="^(.+)">
  <conditions>
    <add input="{HTTP_HOST}" type="Pattern" pattern="^([^.]+)\.myapp\.com$">
  </conditions>
  <action type="Rewrite" url="{C:1}/{R:1}" />
</rule>

Upvotes: 2

Related Questions