Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you're confusing Redirecting and Rewriting here - the behaviour you describe is exactly what I would expect given the rules cited. Initially the request is being <strong>redirected</strong> to www.misite.com/subdomain and then by virtue of your first rule that request is being redirected again to www.misite.com/main/subdomain. I think what you want to be doing here is <strong>rewrite</strong> the requests to serve the correct content for each sub-domain. </p> <p>Redirection effectively means "if a request for URL 'A' arrives, forward the browser on to URL 'B'". Rewriting the request effectively means "if a request for URL 'A' is received then serve <em>resource</em> 'B' as if it were <em>at</em> URL 'A'".</p> <p>I'm assuming you have the following structure-</p> <p>-wwwroot</p> <p>--main</p> <p>--subdomain</p> <p>Presumably what you want happen is that when a user goes to www.domain.com/default.aspx, the default.aspx document in the "main" directory is served, and likewise when the user visits subdomain.domain.com the default.aspx document in the "subdomain" directory is returned.</p> <p>I'm also assuming you don't want the folders themselves to be part of the path, i.e. not subdomain.domain.com/subdomain/default.aspx</p> <pre><code>&lt;rule name="Rewrite to Main directory" stopProcessing="true"&gt; &lt;match url="(.*)" /&gt; &lt;conditions logicalGrouping="MatchAll"&gt; &lt;add input="{HTTP_HOST}" pattern="^www.misite.com(/.*)?$" /&gt; &lt;add input="{PATH_INFO}" negate="true" pattern="/main/" /&gt; &lt;/conditions&gt; &lt;action type="Rewrite" url="/main/{R:1}" /&gt; &lt;/rule&gt; &lt;rule name="Redirect to WWW" stopProcessing="true"&gt; &lt;match url="(.*)" /&gt; &lt;conditions logicalGrouping="MatchAll"&gt; &lt;add input="{HTTP_HOST}" pattern="^misite.com(/.*)?$" /&gt; &lt;/conditions&gt; &lt;action type="Redirect" url="http://www.misite.com/{R:0}" redirectType="Permanent" /&gt; &lt;/rule&gt; </code></pre> <p>I've left the second part of your first code block as a redirect as it is generally considered bad practice to have identical content available at multiple URLs for SEO (see <a href="http://support.google.com/webmasters/bin/answer.py?hl=en&amp;answer=66359" rel="nofollow">http://support.google.com/webmasters/bin/answer.py?hl=en&amp;answer=66359</a>) and will cause you problems with analytics. In this case I have chosen to redirect domain.com/default.aspx to www.domain.com/default.aspx, but it would be equally valid to choose to do it the other way around - you just need to make a choice and apply that consistently within your site. </p> <p>I have dropped the /main/ part of the redirection path/URL as the content in the /main/ directory is what should be served by the request anyway, leaving that in the path would effectively be looking for /main/main/default.aspx. I have also added a negate on the path info condition on the first (rewrite) rule, meaning that if a request that did arrive for www.domain.com/main/default.aspx it would not be rewritten to serve content from the sub-directory - /main/default.aspx would be served instead of the (presumably non-existent) file at /main/main/default.aspx.</p> <p>Lastly the sub-domain is also changed to a rewrite.</p> <pre><code>&lt;rule name="Rewrite for Subdomain" stopProcessing="true"&gt; &lt;match url="(.*)" /&gt; &lt;conditions logicalGrouping="MatchAll"&gt; &lt;add input="{HTTP_HOST}" pattern="^subdomain.misite.com(/.*)?$" /&gt; &lt;add input="{PATH_INFO}" negate="true" pattern="/subdomain/" /&gt; &lt;/conditions&gt; &lt;action type="Rewrite" url="/subdomain/{R:1}" /&gt; &lt;/rule&gt; </code></pre> <p>See <a href="http://weblogs.asp.net/owscott/archive/2010/01/26/iis-url-rewrite-hosting-multiple-domains-under-one-site.aspx" rel="nofollow">http://weblogs.asp.net/owscott/archive/2010/01/26/iis-url-rewrite-hosting-multiple-domains-under-one-site.aspx</a> for more info on this topic.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload