Forum Discussion

Qasim's avatar
Qasim
Icon for Cirrostratus rankCirrostratus
Aug 28, 2019

URL PATH based routing

Hi,

 

wondering if someone can help me here with a basic IRule that routes traffic to a particular pool based on matching a FQDN and URL path?

 

The reason for this is that the same FQDN is used for multiple services.

 

e.g. this is what I use in riverbed world but I have not cracked the Irules yet:

 

if(string.startsWITHl( http.getheader ( "Host" ), "abc.com" ) ){

if(string,contains(http.getpath(), "/test.svc")){

pool.use( "abc_pool" );

} else if(string,contains(http.getpath(), "/efg.svc")){

pool.use( "efg_pool" );

 

will really appreciate your help with this.

 

Regards,

 

14 Replies

  • Snl's avatar
    Snl
    Icon for Cirrostratus rankCirrostratus

    untested

    when HTTP_REQUEST {
      switch [HTTP::host] {
        "abc.com"
      {
          switch -glob [HTTP::uri] {
            "/test.svc"         { pool abc_pool }
            "/efg.svc"         { pool efg_pool }
           }
         }
       }
    }
  • Qasim's avatar
    Qasim
    Icon for Cirrostratus rankCirrostratus

    thanks Snl, just tested but I am getting the following error while saving it:

    6: error: [undefined procedure: 

  • Snl's avatar
    Snl
    Icon for Cirrostratus rankCirrostratus

    I haven't received any error while saving , which tmos version you are using

  • Qasim's avatar
    Qasim
    Icon for Cirrostratus rankCirrostratus

    I am using :

     

    Sys::Version

    Main Package

     Product   BIG-IP

     Version   12.1.3.5

     Build    0.0.10

     Edition   Point Release 5

     Date    Mon May 21 17:36:20 PDT 2018

     

  • Qasim's avatar
    Qasim
    Icon for Cirrostratus rankCirrostratus

    actually ignore me, I was making a typo in the rule. apologies

     

    I will let you know once i have tested the service.

  • Qasim's avatar
    Qasim
    Icon for Cirrostratus rankCirrostratus

    just wondering though, what would my Irule look like if I was to merge the following two Irules into one:

     

    1. when HTTP_REQUEST {
    2. switch [HTTP::host] {
    3. "abc.com"
    4. {
    5. switch -glob [HTTP::uri] {
    6. "/abc.svc" { pool abc_pool }
    7. }
    8. }
    9. }
    10. }

     

    1. when HTTP_REQUEST {
    2. switch [HTTP::host] {
    3. "efg.com"
    4. {
    5. switch -glob [HTTP::uri] {
    6. "/efg.svc" { pool efg_pool }
    7. }
    8. }
    9. }
    10. }

     

    in the above two rules the fqdn is different as well

  • Snl's avatar
    Snl
    Icon for Cirrostratus rankCirrostratus

     

    i am using 12.1.3.4 and its accepting the code

     

  • Qasim's avatar
    Qasim
    Icon for Cirrostratus rankCirrostratus

    Hi,

     

    Apologies it was my bad. I was making a typo i the rule. so what's your though about the below:

     

    what would my Irule look like if I was to merge the following two Irules into one:

     

    1. when HTTP_REQUEST {
    2. switch [HTTP::host] {
    3. "abc.com"
    4. {
    5. switch -glob [HTTP::uri] {
    6. "/abc.svc" { pool abc_pool }
    7. }
    8. }
    9. }
    10. }

     

    1. when HTTP_REQUEST {
    2. switch [HTTP::host] {
    3. "efg.com"
    4. {
    5. switch -glob [HTTP::uri] {
    6. "/efg.svc" { pool efg_pool }
    7. }
    8. }
    9. }
    10. }

     

    in the above two rules the fqdn is different as well

     

     

    • Snl's avatar
      Snl
      Icon for Cirrostratus rankCirrostratus

      try below

      when HTTP_REQUEST { 
      if { [string tolower [HTTP::host]] eq "abc.com" and [HTTP::uri] contains "/abc.svc" } {
              pool abc_pool
                  return
      if { [string tolower [HTTP::host]] eq "xyz.com" and [HTTP::uri] contains "/efg.svc" } {
                        pool xyz_pool
                  return
                 
      }
      }
      }
  • eehir's avatar
    eehir
    Icon for Nimbostratus rankNimbostratus

    Probably something like this

    when HTTP_REQUEST {
    switch [HTTP::host] {
    	"abc.com" {
    		switch -glob -- [HTTP::uri] {
    			"/abc.svc" { pool abc_pool }
    		}
    	}
    	"efg.com" {
    		switch -glob -- [HTTP::uri] {
    			"/efg.svc" { pool efg_pool}
    		}
    	}
    }
    }
    • Qasim's avatar
      Qasim
      Icon for Cirrostratus rankCirrostratus

      thanks Eehir/SNL, I have tried this now, I will let you know once I have a confirmation.

       

      much appreciated

    • Qasim's avatar
      Qasim
      Icon for Cirrostratus rankCirrostratus

      .Hi Eehir,

       

      Can you help out here please. your rule works as expected but the problem is that its locking it down to that specific path. any chance we can change rule to say the "starts with" if so, would that fix the problem? if so, how the rule would look like?

       

      thanks in advance.

      Regards,

      • eehir's avatar
        eehir
        Icon for Nimbostratus rankNimbostratus

        Hi,

         

        Just add * to the end of the path, that should act as a starts with statement.

         

        /abc.svc*

  • Qasim's avatar
    Qasim
    Icon for Cirrostratus rankCirrostratus

    thanks guys,

     

    the rule is working as expected but its locking it down to that specific path. any chance we can change this to e.g. "http path starts with" or contains? whatever you think is better

     

     

    kind regards,