issue with rewrite rule

Topics: Developer Forum, User Forum
Jun 16, 2010 at 3:24 PM

I have 5 domains, they all have unique content and all point to the same ip address

www.domain1.com

www.domain2.com

www.domain3.com

 

THe content all lives in a structure similar to this

www.domain1.com
|
|->wwwroot
|->domain2
|->domain3

In IIS, domain2 and domain3 are virtual directories.
www.domain1.com
|->www.domain2.com
|->www.domain3.com

What I am trying to do is this, when a request comes in for www.domain2.com it should display only the content out of the www.domain2.com folder.

I have this rule setup but it ignores the request and just displays www.domain1.com content

RewriteCond  Host:  (?:www\.)?domain2\.co.il
RewriteRule  (.*)   /www.domain1.co.il/www.domain2.co.il$1 [I,L]

Here is a sample of the logfile
Wed Jun 16 13:29:29 -  3708 - ReadSiteConfig: line   6: StrictParsing is now 'OFF'
Wed Jun 16 13:29:29 -  3708 - ReadSiteConfig: line   8: MaxMatchCount 10
Wed Jun 16 13:29:29 -  3708 - ReadSiteConfig: line   9: IterationLimit 30
Wed Jun 16 13:29:29 -  3708 - ReadSiteConfig: line  22: RewriteCond   %{HTTP_HOST}  ^domain2.co.il$
Wed Jun 16 13:29:29 -  3708 - ReadSiteConfig: line  23: RewriteRule (rule 1)  '^/$'  'http://www.domain1.co.il/www.domain2.co.il[L,R=301]'   (null)
Wed Jun 16 13:29:29 -  3708 - ReadSiteConfig: WARNING: line $d: Rewriting to a fully-qualified URL. Do you want RedirectRule or ProxyRule?
Wed Jun 16 13:29:29 -  3708 - ReadSiteConfig: Done reading, found 1 rules (0 errors, 1 warnings) on 35 lines
Wed Jun 16 13:29:29 -  3708 - GetSiteConfig: Obtain  site '/LM/W3SVC/2083385302/ROOT' (era=5) (rc=1) (Expired=0) (ptr=0x3137B250)...
Wed Jun 16 13:29:29 -  3708 - HttpFilterProc: SF_NOTIFY_URL_MAP
Wed Jun 16 13:29:29 -  3708 - HttpFilterProc: cfg= 0x3137B250
Wed Jun 16 13:29:29 -  3708 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Wed Jun 16 13:29:29 -  3708 - DoRewrites
Wed Jun 16 13:29:29 -  3708 - GetHeader_AutoFree: 'url' = '/'
Wed Jun 16 13:29:29 -  3708 - GetHeader_AutoFree: 'method' = 'GET'
Wed Jun 16 13:29:29 -  3708 - DoRewrites: New Url, before decoding: '/'
Wed Jun 16 13:29:29 -  3708 - DoRewrites: Url (no decoding): '/'
Wed Jun 16 13:29:29 -  3708 - EvaluateRules: depth=0
Wed Jun 16 13:29:29 -  3708 - EvaluateRules: Rule 1 : 1 matches
Wed Jun 16 13:29:29 -  3708 - ReplaceServerVariables: in='%{HTTP_HOST}' out='www.domain2.co.il'
Wed Jun 16 13:29:29 -  3708 - GenerateReplacementString: result 'www.domain1.co.il'
Wed Jun 16 13:29:29 -  3708 - EvalCondition: Cond %{HTTP_HOST} ^domain2.co.il$ => FALSE
Wed Jun 16 13:29:29 -  3708 - EvalConditionList: rule 1, FALSE, Rule does not apply1

Not sure why it is not working.


Chris

Coordinator
Jun 16, 2010 at 6:10 PM
Edited Jun 16, 2010 at 6:16 PM

Hi Chris,

I think you may have introduced an error or two when posting your rules.  The rewritecond you posted isn't legal, and it isn;t the condition that is being evaluated in the logfile you posted.

RewriteCond  Host:  (?:www\.)?domain2\.co.il
RewriteRule  (.*)   /www.domain1.co.il/www.domain2.co.il$1 [I,L]

I think you correctly have %{HTTP_HOST} in that RewriteCond, because that's what the logfile indicates:

...
Wed Jun 16 13:29:29 -  3708 - ReplaceServerVariables: in='%{HTTP_HOST}' out='www.domain2.co.il'
Wed Jun 16 13:29:29 -  3708 - GenerateReplacementString: result 'www.domain1.co.il'
Wed Jun 16 13:29:29 -  3708 - EvalCondition: Cond %{HTTP_HOST} ^domain2.co.il$ => FALSE
Wed Jun 16 13:29:29 -  3708 - EvalConditionList: rule 1, FALSE, Rule does not apply
...

If you examine those last 4 log messages, you may be able to see that IIRF is comparing your HTTP_HOST against the pattern you specified for the RewriteCond, and found that it does not match. The reason, according to the log, is that HTTP_HOST is evaluating to www.domain2.co.il, while the pattern is ^domain2.co.il$. The ^ (caret) indicates beginning-of-string, and since your HTTP_HOST value begins with www, it does not match the given pattern.

This analysis may be not quite completely accurate, because as I said above, when you posted your message you apparently modified the actual stuff you have on your computer, maybe to hide hostnames. As a result, there are inconsistencies in what you posted. In any case you should be able to diagnose the troubles with that RewriteCond, from what I've written here.

As to the RewriteRule - it also looks not-quite-right.  I think you'll want to Rewrite to a url path that begins with the hostname, something more like this:

RewriteCond  %{HTTP_HOST}  (?:www\.)?domain2\.co.il
RewriteRule  /(.*)   /vdir-for-domain2/$1 [I,L]

The vdir-for-domain2 should be replaced with the actual name of your vdir. Be aware: This will work only if the requests for that vdir are handled out of the same app as the requests for the original vdir! If you don't understand this, check the IIRF documentation on RewriteRule for more information.