For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

kg_50758's avatar
kg_50758
Icon for Nimbostratus rankNimbostratus
Jul 25, 2007

Standard HTTPs redirect

I am new to iRules, when i tried the standard https redirect if the url ends with '.do, could not get it to working. iRules i used is as below

 

 

when HTTP_REQUEST {

 

if { [HTTP::uri] ends_with "*.do" } {

 

HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]

 

}

 

}

 

 

Also tried below iRules, just to redirect all the trafic to https, even this is not working for me.

 

when HTTP_REQUEST {

 

set uri [HTTP::uri]

 

HTTP::redirect "https://[HTTP::host]$uri"

 

}

 

 

I want https redirect to happen on the client to f5 and not on the f5 to server.

 

client--->f5--->server

 

 

Searched for the solution in the forum, could not find one. Can some one HELP.

 

Thanks in Advance

 

KG

15 Replies

  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    Looks like you have some missing CR/LF in your rule, as the error message is reporting lines 5 - 9 as a single line of code.01070151:3: Rule [log_request_response] error:

     

    line 5: [wrong args] [set headers "Headers: " foreach aHeader [HTTP::header names] { set headers "$headers$aHeader: [HTTP::header value $aHeader] " } log local0. "Request Info: $request_info; Response Info: status: [HTTP::status] $headers"]You'll need to make sure there's a new line for each line of code in the iRule hoolio provided.

     

     

    HTH

     

    /deb
  • Thanks for all your help.

     

    I got http to https redirect working for all request coming in.

     

     

    Now i want to get the https redirect only for the url containing '.do' in the url. Is there any iRule function to check url which contains '.do'?

     

     

    Thanks again

     

    KG.
  • You can use the HTTP::uri command along with the "contains" operator to check for a .do in the URI. Something like this...

    when HTTP_REQUEST {
      if { [HTTP::uri] contains ".do" } {
         do something...
      }
    }

    -Joe
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Out of curiosity, what was the issue? Also, it might not matter much, but I think it would be more exact to check to see if HTTP::path ends in .do. HTTP::uri contains the complete HTTP object and the query string. HTTP::path contains only the object (and not the query string). So '[HTTP::uri] ends_with .do' would return true for a request like /some/file.php?param=test.do

     

     

    Aaron
  • SSLClient was not assigned for https virtual server after we assigned the client, https redirect for all request started working. Used Path instead of uri and with contains and ends with, code is as below. Thanks your help.

     

     

    when HTTP_REQUEST {

     

    log local0. "client [IP::client_addr] -> [HTTP::host] for uri: [HTTP::uri], path: [HTTP::path]"

     

    if { ([HTTP::path] contains ".do") or ([HTTP::path] ends_with ".jsp") } {

     

    HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]

     

    }

     

    }