Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an discount asp.net account, which uses IIS 7 and I want to configure subdomains to point at specific applications on the site.

For instance:

's1.site.com' would run the application at 'site.com/serverone'. I would like the subdomain to be opaque so that users do not have to deal with the /serverone part.

There was a similar question on server fault, but it involves creating a whole new site for each subdomain, where as I would rather just route to independent applications in subdirectories for each subdomain.

Also discount asp.net provides a script-based programmatic solution, but this is obviously a less desirable and flexible solution, and probably results in reduced performance (though I have not actually measured the difference between the two methods).

share|improve this question

2 Answers 2

I'm not sure how discount aps.net's control panel works, but if you were doing this directly in IIS, you need to create a separate site for each application, not necessarily each subdomain, if there are more than one subdomain per app, then set it up with bindings for each subdoamins URL. The root of each site would then be your apps folder. You can't just use a subfolder of the main site, as you cannot add bindings to a folder.

Alternatively, you can use URL Rewrite to Rewrite request for site.com/serverone to s1.site.com

share|improve this answer
    
By separate 'site', do you mean separate 'application'? I only have access to one 'site', but I like to route the subdomains to different application subdirectories on that 'site'. –  Mark Rogers Mar 24 '10 at 15:22
    
Well I mean a seperate site in IIS, so if you only have one site in IIS, then you will need to look at using URL Rewrite –  Sam Mar 24 '10 at 15:23
    
Could you give a url rewrite rule example for the s1.site.com -> site.com/serverone/ ? You would make my life much easier... I'll beg if you like :) –  Mark Rogers Mar 24 '10 at 15:23
2  
Take a look at this article learn.iis.net/page.aspx/468/… –  Sam Mar 24 '10 at 15:30
    
Ok, thanks, have a nice day –  Mark Rogers Mar 24 '10 at 15:32
up vote 2 down vote accepted

Using the URL Rewrite, that Sam Cogen mentioned, which is automatically installed in any discount asp.net account (and which can be installed to any IIS7 server), I created a rewrite rule to solve my problem.

Note: The staff at discount asp.net said that a rewrite rule is the only way to accomplish this on one of their accounts besides a programmatic script. Discount asp.net provides a programmatic (I say hack) script that will route subdomains to subdirectories, but I needed more flexibility and performance than such a solution would provide.

If the IIS 7 rewrite module is not installed, you will have to find the module (probably at microsoft's IIS website), and then install it.

Once the rewrite module is installed in IIS, connect to it using the IIS Manager.

Make sure you have the root level of the website selected when you create the rule (rather than the subdirectory where your application is), this is very important because it led me to a critical mistake that wasted some time. The rewrite rules can be applied at different levels in the directory hierarchy, causing a rule to have different effects depending on where in the directory hierarchy the rule is located (I believe it makes a change to the local web.config, when a rule is created, but I have not taken the time to confirm this). This also means that you can't see the rules set in other directories when you are altering rules in another directory.

Selecting the root directory for the rewrite is important because you want to reroute all subdomain urls to the subdirectory url (except ones already routed to the subdirectory).

Having selected the root site directory, double click URL rewrite, to enter the rewriting area. Then click Add Rule(s) and create a Blank Rule.

For the matching

Pattern use: ^(?!serverone/)(.*) and set

Requested URL: to 'Matches the Pattern', and

Using to Regular Expressions.

This will route any url through this rule, ignoring those that are already headed to the correct subdomain but we want to restrict the rewrite from routing stuff that doesn't have the subdomain in the url, so next we will add a condition.

It only needs one condition, using {HTTP_HOST} for input, and the pattern for it is: s1.site.com

Finally for the Action, you need an 'Action Type' of 'Rewrite' that appends the query string value.

The rewrite url should be: serverone/{R:0}.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.