Forum Discussion

paul_dcc's avatar
paul_dcc
Icon for Nimbostratus rankNimbostratus
Oct 06, 2014

I can't get this Irule to work

Hi Guy's,

I'm trying to get this Irule to work, but I'm having some problems;

when HTTP_REQUEST {
       if { [HTTP::host] eq "dcc.dorsetforyou.com" and [HTTP::uri] ends_with "/Importer" } {
          HTTP::header replace Host "vmcrglassfish01.dorsetcc.local:18181"
          HTTP::uri "/Importer/"

         }
        if { [HTTP::host] eq "dcc.dorsetforyou.com" and [HTTP::uri] ends_with "/travelclaims" } {
              HTTP::header replace Host "vmcrglassfish01.dorsetcc.local:18181"
    }
        elseif { [HTTP::host] eq "dcc.dorsetforyou.com" } {
              HTTP::redirect "https://dorsetforyou.com"
    }
}

Any idrea ?

13 Replies

  • Hi Paul,

    Just changing the value in the HTTP::header on the request will not affect the routing of the request. I can see what you are trying to do, so I would suggest putting the server that you are trying to direct traffic to in a pool then making your URI modifications if necessary and then directing traffic to the pool (the LTM will take care of the rest).

    Something like this:

    when HTTP_REQUEST {
     if { [string tolower [HTTP::host]] equals "dcc.dorsetforyou.com" } {
            switch -glob [string tolower [HTTP::uri]] {
             "/importer" { pool vmcrglassfish.pool }
             "travelclaims" {
                    HTTP::uri "/SAPTECS/"
                   pool vmcrglassfish.pool
             }
               "/" {
                   HTTP::redirect "https://dorsetforyou.com"
               }
           }
       }
    }
    

    NOTE: You do not have to use switch statements (I like them because they are easier to follow and easier to add to if you know you are going to be doing a lot of manipulation on a given Virtual Server).

    Hope this helps.

    • JRahm's avatar
      JRahm
      Icon for Admin rankAdmin
      it depends on the application. For apps like DNN, it does actually route internally based on host header, so as long as IIS is configured correctly, you can send all requests to back end servers that can then hand to the correct portal by header. That said, based on the OP comments, I think your solution is inline with the ask.
    • JRahm's avatar
      JRahm
      Icon for Admin rankAdmin
      also, no need for glob unless using some wildcards, but since he is using ends_with, I assume */importer and *travelclaims would be necessary.
  • Hi Paul,

    Just changing the value in the HTTP::header on the request will not affect the routing of the request. I can see what you are trying to do, so I would suggest putting the server that you are trying to direct traffic to in a pool then making your URI modifications if necessary and then directing traffic to the pool (the LTM will take care of the rest).

    Something like this:

    when HTTP_REQUEST {
     if { [string tolower [HTTP::host]] equals "dcc.dorsetforyou.com" } {
            switch -glob [string tolower [HTTP::uri]] {
             "/importer" { pool vmcrglassfish.pool }
             "travelclaims" {
                    HTTP::uri "/SAPTECS/"
                   pool vmcrglassfish.pool
             }
               "/" {
                   HTTP::redirect "https://dorsetforyou.com"
               }
           }
       }
    }
    

    NOTE: You do not have to use switch statements (I like them because they are easier to follow and easier to add to if you know you are going to be doing a lot of manipulation on a given Virtual Server).

    Hope this helps.

    • JRahm's avatar
      JRahm
      Icon for Admin rankAdmin
      it depends on the application. For apps like DNN, it does actually route internally based on host header, so as long as IIS is configured correctly, you can send all requests to back end servers that can then hand to the correct portal by header. That said, based on the OP comments, I think your solution is inline with the ask.
    • JRahm's avatar
      JRahm
      Icon for Admin rankAdmin
      also, no need for glob unless using some wildcards, but since he is using ends_with, I assume */importer and *travelclaims would be necessary.
  • Hi Guy's i did get it all to work with this in the end;

     

    when HTTP_REQUEST { if { [HTTP::host] eq "dcc.dorsetforyou.com" and [HTTP::uri] starts_with "/Importer" } { pool glassfish-pool } elseif { [HTTP::host] eq "dcc.dorsetforyou.com" and [HTTP::uri] starts_with "/travelclaims" } { pool glassfish-pool } else { [HTTP::host] eq "dcc.dorsetforyou.com" } { HTTP::redirect "https://dorsetforyou.com" } }

     

  • Code

    when HTTP_REQUEST { if { [HTTP::host] eq "dcc.dorsetforyou.com" and [HTTP::uri] starts_with "/Importer" } { pool glassfish-pool } elseif { [HTTP::host] eq "dcc.dorsetforyou.com" and [HTTP::uri] starts_with "/travelclaims" } { pool glassfish-pool } else { [HTTP::host] eq "dcc.dorsetforyou.com" } { HTTP::redirect "https://dorsetforyou.com" } }

     

  • when HTTP_REQUEST { if { [HTTP::host] eq "dcc.dorsetforyou.com" and [HTTP::uri] starts_with "/Importer" } { pool glassfish-pool } elseif { [HTTP::host] eq "dcc.dorsetforyou.com" and [HTTP::uri] starts_with "/travelclaims" } { pool glassfish-pool } else { [HTTP::host] eq "dcc.dorsetforyou.com" } { HTTP::redirect "https://dorsetforyou.com" } }