Forum Discussion

dusten_25233's avatar
dusten_25233
Icon for Nimbostratus rankNimbostratus
Oct 23, 2008

Fallback Pool with URI redirect.

Hi All,

 

So I have a question. I would like a fallback pool so that if there are no member in the active pool it uses the fallback and directs all traffic to one uri. Here is what I have so far any suggestions would be helpful.

 

 

Thanks

 

 

when HTTP_REQUEST {

 

if { [active_members [LB::server pool]] == 0 } {

 

HTTP::uri "/index.html"

 

pool dmz-stage2

 

}

 

I shall be the new uber global redirector

 

switch -regexp [HTTP::uri] {

 

"^/gift/?" {

 

set id ""

 

 

let's get the last numeric element of the uri

 

regexp {\d+$} [HTTP::path] id

 

 

this if is probably not needed anymore seeing as how we hardcode id

 

if { $id ne "" } {

 

are we special email or feeds...

 

switch -regexp [HTTP::path] {

 

"/feed/?" {

 

HTTP::uri "/gift/index.php?gg_id=$id&sec=feed&[HTTP::query]"

 

}

 

"/email/?" {

 

HTTP::uri "/gift/index.php?gg_id=$id&sec=email&[HTTP::query]"

 

}

 

default {

 

HTTP::uri "/gift/index.php?gg_id=$id&[HTTP::query]"

 

}

 

}

 

}

 

use pool dmz-stage;

 

}

 

 

default {

 

pool dmz-stage;

 

}

 

}

 

}

1 Reply

  • Hi there,

    The rule looks okay. You could potentially eliminate the need for the -regex flag in the switch statements by using two cases for each URI. The glob flag enables string wildcards. I'm not sure whether you're trying to match /feed and /feed/ exactly or whether you want to match /feed*. Here is an example.

    Also, when the pool has no active members, if you rewrite every URI to /index.html, any objects (like stylesheets or images) will also be rewritten and the page won't be rendered correctly. The simplest fix for this might be to move the index and other files to a separate maintenance directory which isn't used anywhere else in the application. You could then only rewrite the URI if the URI doesn't contain that maintenance directory name.

    We discussed this in a recent post:

    Using LB_FAILED and change the URI w/o 302 (Click here)

    Aaron

     
     when HTTP_REQUEST { 
        if { [active_members [LB::server pool]] == 0}{ 
           if {not ([HTTP::path] starts_with "/maintenance_files/"} { 
              HTTP::uri "/maintenance_files/index.html" 
           } 
           pool dmz-stage2 
        } 
      
         I shall be the new uber global redirector 
        switch -glob [HTTP::uri] { 
           "/gift*" - 
           "/gift/*" { 
              set id "" 
      
              let's get the last numeric element of the uri 
              regexp {\d+$} [HTTP::path] id 
      
               this if is probably not needed anymore seeing as how we hardcode id 
              if { $id ne "" } { 
      
                  are we special email or feeds... 
                 switch [HTTP::path] { 
                    "/feed" - 
                    "/feed/" { 
                       HTTP::uri "/gift/index.php?gg_id=$id&sec=feed&[HTTP::query]" 
                    } 
                    "/email" 0 
                    "/email" { 
                       HTTP::uri "/gift/index.php?gg_id=$id&sec=email&[HTTP::query]" 
                    } 
                    default { 
                       HTTP::uri "/gift/index.php?gg_id=$id&[HTTP::query]" 
                    } 
                 } 
              } 
              use pool dmz-stage; 
           } 
           default { 
              pool dmz-stage; 
           } 
        } 
     }