Until few month ago i've been using IIS 6 where i could add different Default Documents to each websites which are physically same directory. Since II7 which adds Default Document value to web config i couldn't use such technique as web.config was changed for all the directory.

So I've found simple solution with rewrite module to change Default Document for each domain

 <defaultDocument enabled="false" />
                <rewriteMap name="ResolveDefaultDocForHost">
                      <add key="site1.com" value="Default1.aspx" />                    
        <add key="site2.com" value="Default2.aspx" />
    <rule name="DefaultDoc Redirect If No Trailing Slash" stopProcessing="true"> 
      <match url=".*[^/]$" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" /> 
      <action type="Redirect" url="{R:0}/" /> 
    <rule name="PerHostDefaultDocSlash" stopProcessing="true"> 
      <match url="$|.*/$" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" /> 
     <add input="{ResolveDefaultDocForHost:{HTTP_HOST}}" pattern="(.+)" /> 
      <action type="Rewrite" url="{R:0}{C:1}" appendQueryString="true" /> 

Now i've got two other issues.

first of all i can't use canonical url rewrite, if i set one then site1.com and site2.com redirected to www.site1.com instead of having www. for each. second problem is that there is a directory within site1' and site2' physical directory called members in which Default.aspx is always a Default Document doesn't matter which domain name was used. It doesn't work as well.

Please help me with this issue because i've never thought i will get such problem with supposed to be better IIS7...


You have two options. One is to keep going down the path that you're on. At a high level the issue with the canonical url rewrite issue is with the action. You can use {HTTP_HOST}, so the action should be something like www.{HTTP_HOST}/{URL}. That makes it dynamic based on the domain name entered rather than having it set to a specific name.

However, you may find it easier to continue to use the default docs. The way to do this per site is to use location tags within applicationHost.config. You can't do it the standard way within IIS Manager because, as you pointed out, it shares the same config for all sites. There are 3 fairly easy ways to do it (not counting the programming options). One is with Configuration Editor, another is with appcmd and the 3rd is with notepad or an editor directly.

I'll describe here how to do it the Configuration Manager way. First, make sure that you have it installed: http://www.iis.net/download/AdministrationPack

Then using IIS manager, navigate to the site you want to change the default doc for. Open Configuration Manager. In the top left drop-down, change to system.webServer/defaultDocument. In the top right, make sure to change to the ApplicationHost.config option. In the main window, select the 'files' row and click the (...). The rest is straight forward.

| improve this answer | |
  • once clicking files row and (...) there seems to be no way to re-order the default docs in the list, would you have to remove them and add them back in the desired order? Would removing or re-ordering affect the global default doc settings? – user133851 Aug 28 '12 at 22:09
  • @gooze. Yes, if you select the Clear All then you can add them back again in the order you want. It won't affect the global doc settings, but it means that the global defaults won't be used, and you'll have the default docs explicitly defined (which isn't a problem since you're making at least one change anyway) – Scott Forsyth - MVP Aug 29 '12 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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