views:

1026

answers:

1

I was writing up this question and in the process, it forced me to think a little harder and I answered it myself, though I still don't completely understand why it solved it.

I have an account on a shared host with 2 domains registered. I'm using the Asp.Net stack to run a few things like a blog and another site I am planning to kick off eventually. Both of my domains point to the root; the first is the original I used to signup, the second is a root domain pointer I added. Here is how I want it to behave:

Directory Structure:

Root                      (www.domain1.com)
Root --\ Blog             (www.domain1.com/blog)
Root --\ Site2            (should be directed here if www.domain2.com)
Root --\ Site2 --\ Junk   (www.domain2.com/junk)

Right now, if you type in www.domain1.com or www.domain1.com/blog, that behaves as expected and I am fine with that. For www.domain2.com, I have the rewrite rule configured like this(from the web.config):

<rule name="Domain2">
    <match url="(.*)(/)?" ignoreCase="false" />
    <conditions logicalGrouping="MatchAll">
     <add input="{HTTP_HOST}" pattern="(www\.)?domain2\.com" ignoreCase="false" />
    </conditions>
    <action type="Rewrite" url="/site2/{R:1}" />
</rule>

That rule is supposed to match any path if the host is domain2.com, pick off the path to the requested resource and format it properly. So when somebody types www.domain2.com/junk/default.aspx, in IIS, this resolves to www.domain2.com/site2/junk/default.aspx without the user ever knowing. This is mostly working as advertised except when the user does not type a trailing slash in a subfolder. IE:

www.domain2.com (works)
www.domain2.com/ (works)
www.domain2.com/junk/ (works)
www.domain2.com/junk (doesn't work!) IIS 7 looses its brain here and formats it out like www.domain2.com/site2/junk because a 2nd request is automatically issued for the trailing slash and a 404 happens.

So, I updated the action to be:

<action type="Rewrite" url="/site2/{R:1}/" />

This seems to have resolved it, but why doesn't IIS 7 now spit out www.domain2.com/junk2/default.aspx/ ? How does it know not to append a trailing slash to a document extension?

+2  A: 

www.domain2.com/junk does not work because you added slash in match, but actual url to match does not contain it. It just contains "junk".

Also you need to add:

<rule name="Domain2" stopProcessing="true">

so it does not evaluate other rules if match is found. I suspect that you may see that what confuses you, is other rules you have setup.

Tomas Kirda