IIS 7 Url Rewriting and Two Domains

I wrote this question in the process, it made me think a little more complicated, and I myself answered, although I still do not understand why he decided this.

I have an account on a shared host with two domains registered. I am using the Asp.Net stack to launch a few things, such as a blog and another site, which I plan to eventually start. Both of my domains point to the root; the first is the original that I used to register, the second is the root domain pointer that I added. This is how I want him 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, it behaves as expected, and I'm fine with that. For www.domain2.com, I have a rewrite rule configured like this (from 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> 

This rule must match any path, if the host is domain2.com, select the path to the requested resource and format it correctly. Therefore, when someone dials www.domain2.com/junk/default.aspx, in IIS this is allowed at www.domain2.com/site2/junk/default.aspx without the user's knowledge. This basically works as advertised, unless the user does not enter a trailing slash in the subfolder. IE:

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

So, I updated the action:

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

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

+4
source share
1 answer

www.domain2.com/junk does not work because you added a slash to the match, but the actual url for matching does not contain it. It just contains garbage.

Also you need to add:

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

therefore, it does not evaluate other rules if a match is found. I suspect that you can see what bothers you, these are the other rules that you have set.

+3
source

All Articles