Forum Discussion

Francois_Begin_'s avatar
Francois_Begin_
Icon for Nimbostratus rankNimbostratus
Jul 06, 2005

Redirect questions

Hi all,

I am trying to create a re-direct that will achieve this:

Take a request for http://banana.fruits.com/Data and re-direct it to http://:1601/

At this time, we re-direct to a single server, but we will be re-directing to a pool of servers in the future.

The request comes in on port 80 and goes to port 1601 on the back end server.

The '/Data' of the initial request needs to be stripped. The html documents being accessed are located at the root of the back end server.

So far, I made it work with this simple irule:

 
 when HTTP_REQUEST { 
    if { [HTTP::uri] contains "ASFData" } { 
      HTTP::redirect http://142.178.100.139:1601 
    } 
 } 
 

This works but there are a few problems:

Firstly, this works only for a single host. How would I re-direct to multiple hosts? And how would I ensure availability if one of the hosts was to go down?

Secondly, when a user type in http://banana.fruits.com/Data in his/her browser, this gets changed to http://:1601. Can I do this re-direct transparently for the user i.e. he/she would still see http://banana.fruits.com/Data in his/her browser but get re-directed to the back end server.

Thanks,

François Bégin

  • I tried selecting a pool but that did not work as I need to deal with '/Data'. Selecting a pool means the request goes from

     

     

    http://banana.fruits.com/Data

     

    to

     

    http:///Data

     

     

    If I could truncate '/Data', then that would work.

     

     

    François
  • drteeth_127330's avatar
    drteeth_127330
    Historic F5 Account
    Yes, you can rewrite the request. If there are no path components following data, then something like this should work:

    HTTP::request "/"

    If there are path components following data, then you will have to perform some string manipulation to preserve them.
  • Ok, here is the irule I am trying to enter:

     

     

     

    when HTTP_REQUEST {

     

    if { [HTTP::uri] contains "Data" } {

     

    HTTP::request "/"

     

    use pool backend_servers

     

    }

     

    }

     

     

     

    But for some reason, the F5 is not allowing me to enter that rule. I get the following error:

     

     

    01070151:3: Rule [asfdata_redirect_tmp] error:

     

    line 3: [undefined procedure: HTTP::request] [HTTP::request]

     

     

    This F5 is running BIG-IP 9.0.4 Build 118.5

     

     

    François
  • Still no success. Here is my rule

     

     

    when HTTP_REQUEST {

     

    if { [HTTP::uri] contains "Data" } {

     

    HTTP::uri "/"

     

    use pool backend_servers

     

    }

     

    }

     

     

     

    I added a few log directives to track down what was happening. I see the request coming in for http://banana.fruits.com/Data and HTTP:uri is initially set to '/Data'. The log does not indicate that HTTP::uri gets changed to "/" and snooping on the back end server shows no http traffic hitting the server.

     

     

    Francois

     

     

     

     

     

     

     

  • drteeth_127330's avatar
    drteeth_127330
    Historic F5 Account
    Did you add the log directives in the iRule or on the back-end webserver? I have tested the rule on my big-ip and it appears to work as intended. What version of big-ip are you running? I seem to recall a bug with the contains operator, but it was fixed long ago.
  • Log directives were on the F5

     

     

    when HTTP_REQUEST {

     

    if { [HTTP::uri] contains "Data" } {

     

    log "I received a request for Data"

     

    log [HTTP::uri]

     

    HTTP::uri "/"

     

    log [HTTP::uri]

     

    pool app_asfdata_dvlog

     

    }

     

    }

     

     

    All I see in the logs is

     

     

    I received a request for Data

     

    /Data

     

     

     

    I was expecting to see

     

     

    I received a request for Data

     

    /Data

     

    /

     

     

     

    Running BIG-IP 9.0.4 Build 118.5

     

     

     

     

  • This appears to be working now. I was missing a default SNAT, and a default pool for the irule.