Forum Discussion

scarpozzi_82104's avatar
scarpozzi_82104
Icon for Nimbostratus rankNimbostratus
Dec 09, 2010

Redirection when clients are at /

I've got a portal server that will be unavailable weekly due to some oracle cold backups. I've got an iRule that sets up the maintenance window and gives me controls to automate the recurring window.

 

 

My portal server listens on 80/443 in 2 pools/virtual servers. When the database goes down for backups, I have Apache spin up another instance listening on port 81 for the maintenace page...so I created a maintenance pool.

 

 

To handle requests during the maintenace window, the command I have is:

 

 

use pool maint_pool

 

 

I tested this and it works great. The problem is, when a user is logged into the portal and it goes down for maintenance, they get a 404 because the pool switches out from under them. I need a redirect for established connections and the 'use pool maint_pool' for new connections.

 

 

To get what I want, I'm going to need a redirect when the maintenance window is on and the HOST:URI doesn't match portal.site.com. What iRule functions allow you to compare the client URL and do a redirect when it isn't 'portal.site.com' or 'portal.site.com/'

 

 

Thanks.

 

2 Replies

  • An HTTP client cannot send a null URI. Something like this should do:

    when HTTP_REQUEST {
    
        Check for anything not portal.site.com/
       if {"[string tolower [HTTP::host]][HTTP::uri]" eq "portal.site.com/"}{
    
          pool maint_pool
    
       } else {
    
          HTTP::redirect "http://portal.site.com/"
       }
    }
    

    This assumes that portal.site.com/ doesn't reference any other URIs under portal.site.com. If it did, you could add them to a switch statement:

    when HTTP_REQUEST {
        Check for host of portal.site.com
       if {[string tolower [HTTP::host]] eq "portal.site.com"}{
           Check if URI is a maintenance URI
          switch -glob [HTTP::uri] {
             "/maint/*" -
             "/maintenance.jpg" -
             "/maintenance.css" -
             "/maintenance.html" {
                pool maint_pool
                return
             }
          }
       }
        If we're still in the iRule, the request wasn't for a maintenance URI, so redirect the request
       HTTP::redirect "http://portal.site.com/"
    }

    Aaron
  • Thank you so much!

     

     

    The second example was exactly what I was looking for. I was able to do the redirect and still provide the maintenance URI needed. I really appreciate it!

     

     

    -Scarpozzi