Simple redirect questionRSS

17 replies

Last post Jul 27, 2009 11:40 AM by wonyoo

  • Simple redirect question

    Jul 20, 2009 07:01 AM|danyw|LINK

    Hi everyone, I am a newbie when it comes to sys-admin stuff. Basically I'd like to filter by host name and redirect appropriately. I'm not sure about the jargon but here's what I'm after:

    Requests that come to host1.domain.com should be redirected to 192.168.1.2, those to host2.domain.com go to 192.168.1.3.

    I've got a couple of rules with regexp of (.*)(host1.domain.com)(.*) redirecting to {R:1}192.168.1.2{R:3}. This works just fine - all the requests get redirected accordingly.

    I have also created a matching rule for host2. This is where the trouble begins. It just happens that 192.168.1.3 is the IIS machine that's handling all this. Going to http://host2.domain.com still redirects it to 192.168.1.2 - not as defined in the rule.

    It is very likely I have missed something terribly obvious. Can someone please help me with this? Any suggestions would be greatly appreciated.

    Cheers,
    Dany.

  • Re: Simple redirect question

    Jul 20, 2009 09:44 AM|anilr|LINK

    Can you paste your exact rule(s)?

    Anil Ruia
    Software Design Engineer
    IIS Core Server
  • Re: Simple redirect question

    Jul 20, 2009 05:26 PM|danyw|LINK

    Unfortunately I did everything through the UI so I can't paste the exact content. I'm not entirely sure where to look for the redirect rules.

  • Re: Simple redirect question

    Jul 22, 2009 03:33 AM|danyw|LINK

    Found my rewrite rules - they were in c:\inetpub\history where I picked one from a subfolder with the latest timestamp.

    Here it is:

            <rewrite>
                <globalRules>
                    <clear />
                    <rule name="ARR_Code Dogs Limited WF_loadbalance" patternSyntax="Wildcard" stopProcessing="true">
                        <match url="*" />
                        <conditions logicalGrouping="MatchAll" />
                        <action type="Rewrite" url="http://Code Dogs Limited WF/{R:0}" />
                    </rule>
                    <rule name="SavitarMail" stopProcessing="false">
                        <match url="(.*)(savitarmail.sytes.net)(.*)" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{HTTP_HOST}" pattern="savitarmail.sytes.net" />
                        </conditions>
                        <action type="Rewrite" url="{R:1}192.168.1.57{R:3}" />
                    </rule>
                    <rule name="SavitarBernese" stopProcessing="true">
                        <match url="(.*)(savitarbernese.sytes.net)(.*)" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{HTTP_HOST}" pattern="savitarbernese.sytes.net" />
                        </conditions>
                        <action type="Redirect" url="{R:1}192.168.1.58{R:3}" redirectType="Permanent" />
                    </rule>
                </globalRules>
                <rewriteMaps>
                    <rewriteMap name="CodeDogs">
                        <add key="savitarbernese.sytes.net" value="192.168.1.58" />
                        <add key="savitarmail.sytes.net" value="192.168.1.57" />
                    </rewriteMap>
                </rewriteMaps>
            </rewrite>

    I'm not sure why that load balancing rule is there - any suggestions would be greatly appreciated.

    Thanks,
    Dany.

  • Re: Simple redirect question

    Jul 23, 2009 02:19 AM|wonyoo|LINK

    I see a few things.

    1) The URL rewrite rules are process from top to bottom.  So in your case, all incoming requests are being forwarded to "Code Dogs Limited WF" - and the following 2 rules are not being exercised at all.   Question - are you planning on using the "Code Dogs Limited WF".  I don't think you do.  If you are not planning on using it, then please remove the rule from config.

    2) In order to use ARR as a proxy (which is what you are trying to do), you have to enable the proxy feature.  Depending on whether you have ARRv1, ARRv2 Beta1 or ARRv2 Beta2, the location of this checkbox is slightly different.  Please let me know which one you are using. 

    3) As for your last rule, you are using an action type of redirect - do you mean to do that?  Or do you want that to be proxied through ARR as well?

    ARR

  • Re: Simple redirect question

    Jul 23, 2009 06:51 AM|danyw|LINK

    Thanks for the quick response wonyoo - I will give this a try soon as I am not anywhere near the machine at the moment. I only downloaded the ARR module last month so I assume it's ARRv1.

    I'm not entirely sure which one I need to achieve this, redirect or rewrite. I simply want to requests to go to the appropriate machines depending on the hostname in the request.

    Thanks,
    Dany.

  • Re: Simple redirect question

    Jul 23, 2009 11:00 AM|wonyoo|LINK

    Dany

    Yes, try that out and let me know if it works.  Sounds like you probably have v1.  What that means is when you click on the server node of the tree view in the navigation pane, you will see an "Application Request Routing" icon.  Double click on that and on the top of the page, there will be a check-box for enabling (what we call, "sever level") proxy.  You will want to do that.

    As for rewrite vs. redirect - if you want to proxy the request, then you want rewrite (ie. the URL on the browse remains that of proxy).  If you want to send 302 back to your client, then you want redirect.  The difference, of course, is that in proxy case, your client thinks that they are connecting to the proxy.  In redirect, the client is redirected (ie. the URL on the browser will change).  Sounds like you want rewrite.

    application Request Routing reverse proxy

  • Re: Simple redirect question

    Jul 24, 2009 05:21 AM|danyw|LINK

    Ok, I think I tried what you suggested correctly - unfortunately there are a couple of points I am not sure about:

    1. On the Server Level proxy page do I accept all the default values for the rest of the page?

    2. Do I need to tick "Use URL Rewrite to inspect incoming requests"? If so, what value do I use for Reverse proxy?

    3. I want all traffic to a particular domain (savitarbernese.sytes.net) to be forwarded to 192.168.1.58, but everything else to stay on the same server. Do I need a rewrite rule as well as enabling the proxy?

    Sorry about all this - I'm not a system admin and seriously lack understanding of the basic proxy principles. If I tick "Use URL Rewrite..." it creates an entry that stops processing subsequent rules. Not entirely sure that's what's supposed to happen. I think the whole UI is confusing me, on top of my lack of understanding.

    Can you please help me a bit further on this one?

  • Re: Simple redirect question

    Jul 24, 2009 12:45 PM|wonyoo|LINK

    No problems.

    I think I understood you fully, but I wanted to repeat it to ensure that I do.

    • <div mce_keep="true">You are using ARR in a hybrid mode.  Meaning, it is both a proxy (for savitarbernese.sytes.net) and for all others, it is a content server.</div>
    • <div mce_keep="true">For requests with hostname savitarbernese.sytes.net, you want them to be forwarded to 192.168.1.58.</div>

    Is that it?

    Assuming that above is what you want, here are the couple of steps that you will need to take.

    Before you start though, make sure that you don't have any server farms created and/or any URL rewrite rules have been written.  If so, please remove them.  I am assuming that you have a clean start.

    1) Let's enable proxy.  For that, on the page that you have already located, check "Enable proxy" checkbox.  Accept all the default values, except:

    - select "Use URL Rewrite to inspect incoming requests"

    - in "Reserver proxy:", enter 192.168.1.58

    Doing just the above has now setup the ARR.  However, ALL requests are being forwarded to 192.168.1.58.

    2) So in order to only forward the requests with hostname savitarbernese.sytes.net, let's further modify the URL rewrite rule.  Select the server node in the navigation tree view.  Select URL rewrite icon.  Note that there is one rule that has been created (from step 1 above).  It should be named something like "ARR_server_proxy".  Select the rule and click "Edit".

    Once you are in the "editing" mode, sleect "Add Conditions", the click "Add...".   In "Add Condition" dialog, enter {HTTP_HOST}, Matches the pattern savitarbernese.sytes.net.  Click on OK to save.  The "Add Condition" dialog is now closed and you are back to Edit Rule page.  Click on Apply on the right hand side to save the changes.

    Basically what you have done in step 2 is to add a contion to the rule so that the rule is applied only when the condition is true (in which case the host header is "savitarbernese.sytes.net").

     

    That should do the trick.  Let me know if you have further questions.

    ARR reverse proxy application Request Routiing

  • Re: Simple redirect question

    Jul 24, 2009 05:04 PM|danyw|LINK

    Wow - that's a very thorough set of instructions. Thanks again.

    I have actually tried that before and it half worked. Requests to savitarbernese.sytes.net are forwarded to 192.168.1.58. Unfortunately so is everything else! It doesn't seem to filter only those with the matching hostname...

    Here's the latest incarnation of the rules:

            <rewrite>
                <globalRules>
                    <clear />
                    <rule name="ARR_server_proxy" patternSyntax="Wildcard" stopProcessing="true">
                        <match url="*" />
                        <action type="Rewrite" url="http://192.168.1.58/{R:0}" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="savitarbernese.sytes.net" />
                        </conditions>
                    </rule>
                </globalRules>
                <rewriteMaps>
                </rewriteMaps>
            </rewrite>
            <proxy enabled="true" />

  • Re: Simple redirect question

    Jul 24, 2009 06:19 PM|wonyoo|LINK

    Have you tried it with the new rule?   It didn't work the first time b/c you had other rules in URL rewrite (the rules are processed from top to bottom):

                     <rule name="ARR_Code Dogs Limited WF_loadbalance" patternSyntax="Wildcard" stopProcessing="true">
                        <match url="*" />
                        <conditions logicalGrouping="MatchAll" />
                        <action type="Rewrite" url="http://Code Dogs Limited WF/{R:0}" />
                    </rule>
                    <rule name="SavitarMail" stopProcessing="false">
                        <match url="(.*)(savitarmail.sytes.net)(.*)" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{HTTP_HOST}" pattern="savitarmail.sytes.net" />
                        </conditions>
                        <action type="Rewrite" url="{R:1}192.168.1.57{R:3}" />
                    </rule>

    Another way to troubleshoot this is to enable Failed Request Tracing and see how the URL rules are being evaluated. 

    I basically have the same setup and it seems to work as expected:

                <globalRules>
                    <rule name="ARR_server_proxy" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
                        <match url="*" />
                        <action type="Rewrite" url="http://wonyoo-w2k8/{R:0}" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="arr1" />
                        </conditions>
                    </rule>
                </globalRules>

    (in my case, if users are connecting to the server using "arr1" as the domain, then they get routed to wonyoo-w2k8 server.

    ARR application Request Routiing

  • Re: Simple redirect question

    Jul 24, 2009 06:54 PM|danyw|LINK

    Yup, I tried it with the new rule as listed in my latest post. It actually works, ie. savitarbernese.sytes.net is indeed forwarded to 192.168.1.58. Unfortunately so do everything else! It doesn't just forward requests with savitarbernese.sytes.net.

    How do I stop requests with other host headers from being forwarded? I thought the condition to match the appropriate http_host is supposed to only forward those that match the condition?

  • Re: Simple redirect question

    Jul 24, 2009 07:06 PM|wonyoo|LINK

    Your understanding is absolutely right.  So I susect that the URL rewrite rules are somehow not being processed properly.  In order to step through this, you can enable Failed Tracing Rule.  The steps for this can be found at http://learn.iis.net/page.aspx/467/using-failed-request-tracing-to-trace-rewrite-rules/

    This will allow you to step through the rules as the request is going through the pipeline.  So you can identify how the rules are being processed for other host header.  Given that everything is being forwarded, I would have to guess that somehow the rules are not being matched correctly.

    Once you enable Failed Tracing Rules and collect some data, let me know if you have trouble reading through the data.  I can help you with that.

    application Request Routiing

  • Re: Simple redirect question

    Jul 24, 2009 08:47 PM|danyw|LINK

    I have turned on the Failed Request Tracing but the log folder is empty. I have a suspicion it's not actually "failing" as such, just not doing quite what it's supposed to be.

    Admittedly I didn't follow the instructions exactly like that article said. I figured all I need to do is make a request to savitarbernese.sytes.net and savitarmail.sytes.net to test it. Both went to 192.168.1.58 - nothing stayed within 192.168.1.57.

    I have a feeling I have missed something obvious - just can't think of what...

  • Re: Simple redirect question

    Jul 24, 2009 09:16 PM|wonyoo|LINK

    Depending on the FREB rule, you may not get any log.  Are you collecting logs for response 200-999?  The term "failed request" may seem confusing.  The request does not have to fail, per se - it generates the traces based on the rule/criteria.  So if you configure it to collect anything between 200-999,  you should get the log.   Based on the log, we can figure out what's going on with the URL rewrite rules.

    ARR application Request Routing reverse proxy

  • Re: Simple redirect question

    Jul 24, 2009 09:42 PM|danyw|LINK

    For some reason I only had 200-399 - I think that's what instructions on that page said. I have changed it to 200-999 and still no log.

    I have select WWW Server as the provider, and selected Rewrite and RequestRouting areas. Still nothing though. Is there a setting somewhere for log file location? I looked in c:\inetpub\logs\FailedReqLogFiles and it's empty...

  • Re: Simple redirect question

    Jul 25, 2009 02:48 AM|danyw|LINK

    D'oh! Embarassing as it is I have to admit I made a big booboo - I forgot to change my router's port forwarding to the IIS machine! The rule is behaving correctly now. The only strange thing is the total lack of FREB log file - not sure what's happening there...

    Can I just confirm this please? If I need another rule to forward to another machine based on another {HTTP_HOST} condition can I just:

    1. Untick the "Stop processing subsequent rules"
    2. Create another rule, identical to the first except for the {HTTP_HOST} match condition, and tick the "Stop processing subsequent rules"

    Can I mix the use of ARR and Rewrite with host headers on various "sites" running on different ports on the same machine?

    Thanks again.

  • Re: Simple redirect question

    Jul 27, 2009 11:40 AM|wonyoo|LINK

    Dany

    1) Regarding FREB, it's probably you installed FREB after the modules have been installed.  Were you able to see rewrite and ARR areas when you were enabling FREB?  (I am guessing no).  In order to correct this problem, all you need to do is to repair the ARR and URL rewrite installs.  (You can do this from add/remove programs.)

    2) As for {HTTP_HOST}, you will want to select "stop processing subsequent rules" for your scenario.  The rules are applied in order of they are listed and also the "rewrittten" URL from the previous rule can continue to be "processed" in subsequent rules.  In your case, what you want to do is to "stop processing" the rules if the condition is met ({HTTP_HOST} is of some name that you want to match).  So yes, you can add more rules with {HTTP_HOST} pattern matching, but you will want stop process (for every rule) since you will want to exit the processing, when the request matches the condition.

    3) Yes, you can "mix" the use of ARR and sites.  ARR is what we call "sever level" feature - so it is available to all sites.  In order to scope it to a certain site, you can use HTTP_HOST, as you are doing.

     

    application Request Routiing