Forum Discussion

Scott_85950's avatar
Scott_85950
Icon for Nimbostratus rankNimbostratus
Sep 23, 2011

iRule - HTTPS redirect to HTTP

Is it possible to redirect a URL currently rendering in HTTPS, back to HTTP?
I know that some browser types will notify users that they are about to leave
an HTTPS page, however the benefits outweigh the down falls.  
If I place the following iRule in my 443 profile, it will not redirect to HTTP as
directed, assuming HTTPS.  Apologies if this is a junior mistake.  Just need some 
advise.
when HTTP_REQUEST {
  if {[HTTP::host] eq "www.yyy.com"} {
    HTTP::redirect "http://zzz.ccc.com[HTTP::uri]"
  }
}

8 Replies

  • Hi Scott,

     

     

    If you have a client SSL profile on your HTTPS virtual server and apply that iRule, it should redirect any www.yyy.com host request to http://zzz.ccc.com with the URI preserved.

     

     

    What are you seeing happen? Do you see any errors when applying the iRule, or in /var/log/ltm when you test it?

     

     

    Aaron
  • Morning Aaron,

     

     

    Apologies, I have revised the sample iRule for more clarity as to what I am trying to achieve. I am not actually looking to redirect to another domain, rather, redirect from the 443 profile to the 80 profile when a virtual directory is identified in the GET request. How would I redirect from HTTPS to HTTP using the following iRule?

     

     

    when HTTP_REQUEST {

     

    if {[HTTP::uri] contains "/pdf"} {

     

    HTTP::redirect "http://[HTTP::host]/pdf/[URI::basename [HTTP::uri]] }

     

    }

     

    }

     

     

  • Hi Scott,

    I did add some protection into this iRule that will prevent an endless loop if you put this iRule on both the HTTP and HTTPS Virtual Server. It will check to see if "/pdf" exists anywhere in the URI and verify that the local port that the request came in on was 443. If both qualify it will redirect you to your HTTP Location.

     
    when HTTP_REQUEST {
    if { [string tolower [HTTP::uri]] contains "/pdf" && [TCP::local_port] == 443 } {
    HTTP::redirect "http://[getfield [HTTP::host] ":" 1]/pdf/[URI::basename [HTTP::uri]]"
    }
    }
    

    Hope this helps.
  • Hi Michael,

     

     

    I am receiving this iRule validation error when attempting to create it in the F5. It looks like it needs to have opening / closing "$" to complete the statement. Have you seen this before?

     

     

    01070151:3: Rule [TEST_HTTPS_TO_HTTP_REDIRECT] error: line 2: [parse error: PARSE syntax 78 {syntax error in expression " [string tolower [HTTP::uri]] contains "/pdf" && [TC...": variable references require preceding $}] [{ [string tolower [HTTP::uri]] contains "/pdf" && [TCP::local_port] == 443 }]
  • The iRule submitted successfully to my 443 virtual server. When the criteria meets both /pdf and port 443, it seems to ignore the iRule completely, returning the same response in 443. I made sure the iRule was at the top of the priority list sort order to ensure no conflicts.