Forum Discussion

Pandiarajan_701's avatar
Pandiarajan_701
Icon for Nimbostratus rankNimbostratus
Jun 26, 2012

Irule Redirection

Dears,

 

 

 

I need to redirect an URL

 

 

 

www.bana.com/stp/* >>> www.gamil.com/*

 

 

 

We need to change the HTTP Host from "bana.com" to "gamil.com" and remove the "stp" from the URI and then keep whatever follows in the URI after the "stp"

 

 

 

 

 

Below is one of the Example:

 

 

 

http://www.bana.com/stp/stweb/index.jsp should be redirected to http://gamil.com/stwebclient/index.jsp

 

5 Replies

  • Hi Pandiarajan,

    You can try something like this:

    when HTTP_REQUEST {
    if {[string tolower [HTTP::host][HTTP::uri]] starts_with "www.bana.com/stp/"}{
    log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting request to http://gamil.com[string range 4 end [HTTP::uri]"
    HTTP::redirect "http://gamil.com[string range 4 end [HTTP::uri]"
    }
    }
    

    Aaron
  • Hi Aaron,

     

     

    Thanks for the reply.

     

     

    I have modified ur irule as below.

     

     

    when HTTP_REQUEST {

     

    if {[string tolower [HTTP::host][HTTP::uri]] starts_with "www.bana.com/stp/"}{

     

    log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting request to http://gamil.com[string range 4 end [HTTP::uri]]"

     

    HTTP::redirect "http://gamil.com[string range 4 end [HTTP::uri]"

     

    pool STP_Pool

     

    }

     

    }

     

     

    I am getting the parse error as shown below

     

     

    [iRuler_Parse_Test_Rule] error: line 4: [parse error: missing close-bracket] [[string range 4 end[HTTP::uri]" pool STP_Pool ]

     

    Rule [iRuler_Parse_Test_Rule] error: line 4: [parse error: missing "] ["http://gamil.com [string range 4 end[HTTP::uri]"] pool STP_Pool ]

     

     

     

    Please check this and advise.

     

    Waiting for your reply.

     

    Thanks in advance.

     

     

    Regards,

     

    Pandiarajan
  • you are missing close bracket on HTTP::redirect line. it could be like this.

     

     

    HTTP::redirect "http://gamil.com[string range 4 end [HTTP::uri]]"

     

     

    by the way, since you are doing redirection, why do you need "pool" command?
  • Hi I will check this and update...

     

     

    I dont want this URL to be directed to the default pool. We have a seperate pool for this URL as STP_Pool and i need this URL to hit that pool. Hope this will fix.

     

     

    Regards,

     

    Pandiarajan .K

     

     

  • HTTP::redirect will send redirection response to client. then, client will create a new connection to url which is specified in location header i.e. www.gamil.com/*. if you want this new connection to be directed to STP_Pool, the virtual server which handling www.gamil.com has to configure with STP_Pool.