How to manipulate default document with rewrite module on IIS7?

Posted by eugeneK on Server Fault See other posts from Server Fault or by eugeneK
Published on 2010-11-01T10:02:53Z Indexed on 2011/02/06 7:27 UTC
Read the original article Hit count: 576

Filed under:
|
|

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

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...

© Server Fault or respective owner

Related posts about iis7

Related posts about url-rewriting