Forum Discussion

Ravi_Rajan_7549's avatar
Ravi_Rajan_7549
Icon for Nimbostratus rankNimbostratus
Apr 08, 2008

HTTP to HTTPS redirect

Hi,

 

 

I want to have an irule to redirect all incoming traffic from http to https, host and the URI remaining the same.

 

 

I browsed through the forum and could not find the above. Please help in this.

 

 

Regards,

 

Ravi

7 Replies

  • Here is an example. You apply this on VIP on port 80. This is assuming you have the same VIP on port 443

    
    when HTTP_REQUEST {
          HTTP::redirect "https://domain.com[HTTP::uri]"
    }
  • Posted By ravi.rajan on 04/07/2008 9:17 PM

     

    Hi,

     

    I want to have an irule to redirect all incoming traffic from http to https, host and the URI remaining the same.

     

    I browsed through the forum and could not find the above. Please help in this.

     

    Regards,

     

    Ravi

     

     

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    Is there a reason you re-posted the original post as a quote? Did I miss something?

     

     

    Colin
  • Hi,

     

     

    I encountering a a peculiar issue here using this irule.

     

    I am using the rule as below -

     

     

    when HTTP_REQUEST {

     

    if {[matchclass [ string tolower [HTTP::uri] ] contains $::applist]} {

     

    HTTP::redirect https://172.25.100.220[HTTP::uri] }

     

    }

     

    }

     

     

    Now the issue is -

     

     

    Applist contains a string of all virtual directories (IIS6) for ex. abc, pqr, test.

     

     

    now i type the URL http://VIP1/xyz/per/ajskc/test.aspx

     

     

    By the irule, the above should not match and should not redirect to HTTPS, but it is redirecting to HTTPS.

     

     

    When i put a log statement in irule for [HTTP::uri], i got this value /xyz/per/ajskc/test.aspx

     

     

    Can we modify the irule in someway so that i can strip the entire URI and consider only the first part for compare.

     

     

    Require help urgently.

     

     

    TIA,

     

     

    Ravi

     

  • Hi,

    to handle only the first part of the uri between "/" you should try to use the command getfield: Click here

    
    set first_part [getfield [HTTP::uri] "/" 2]
    log local0. "first part is $first_part"

    in your example: /xyz/per/ajskc/test.aspx first_part should be xyz

  • Thanks,

     

     

    I did it slightly the other way using findstr as below -

     

     

    when HTTP_REQUEST {

     

    if {[matchclass [findstr [ string tolower [HTTP::uri]] / 1 /] contains $::cls1apps]} {

     

    HTTP::redirect http://172.25.103.252[HTTP::uri] }

     

    }

     

     

    Thanks,

     

    Ravi