Forum Discussion

Sydneysider_895's avatar
Sydneysider_895
Icon for Nimbostratus rankNimbostratus
Jun 18, 2010

HTTP to HTTPS redirection

Hi There,

 

Can some please help me write an irule to do the below, redirect a http page to a https page on the LTM

 

 

http://blahblah.blah.com.au/LiveStats/login.aspx

 

 

to

 

 

 

https://blahblah.blah.com.au/LiveStats/login.aspx

 

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Here is something you can start with on the HTTP VS:

    
    when HTTP_REQUEST {
    
       if {[string tolower [HTTP::path]] eq "/LiveStats/login.aspx"}{
    
          HTTP::redirect "https://[HTTP::host]/LiveStats/login.aspx"
       }
    }
    

    Aaron
  • Thanks Aaron, i am trying the below but get an error donno if i am doing something wrong , i went in to VS and then to a new IRule

     

     

    when HTTP_REQUEST {

     

    Check for host 'x.x.com.au/Livestats/login.aspx'

     

    if { ([HTTP::host] equals "x.x.com.au") and ([HTTP::uri] equals "LiveStats/login.aspx") } {

     

     

    If match redirect

     

    HTTP::redirect https://x.x.com.au/LiveStats/login.aspx

     

    }
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    The iRule looks fine. If it's an IIS based app, you could set the path to lowercase.

     

     

    What's the error? Is it coming from the application or LTM?

     

     

    Aaron
  • 01070151:3: Rule [DM_iRule] error:

     

    line 1: [parse error: missing close-brace] [{ Check for host 'xx.x.com.au/Livestats/login.aspx'

     

    if { ([HTTP::host] equals "xx.x.com.au") and ([HTTP::uri] equals "LiveStats/login.aspx") } {

     

     

    If match redirect

     

    HTTP::redirect https://xx.x.com.au/LiveStats/login.aspx

     

    }]

     

    line 3: [command is not valid in the current scope] [if { ([HTTP::host] equals "xx.x.com.au") and ([HTTP::uri] equals

     

    "LiveStats/login.aspx") } {

     

     

    If match redirect

     

    HTTP::redirect https://xx.x.com.au/LiveStats/login.aspx

     

    }]

     

     

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    The rule was missing a close curly brace and the path was missing the leading forward slash. Can you try this:

    
    when HTTP_REQUEST {
    
        Check for host 'x.x.com.au/Livestats/login.aspx'
       if { ([string tolower [HTTP::host]] equals "x.x.com.au") and ([string tolower [HTTP::path]] equals "/livestats/login.aspx") } {
    
           If match redirect
          HTTP::redirect "https://x.x.com.au/LiveStats/login.aspx"
       }
    }
    

    Aaron
  • I'd recommend using the iRule Editor. It helps with command lookups, syntax, auto-complete (Like Intellisense), syntax checking before uploading / saving the iRule to the LTM, and even allows you to save and edit iRules Off-Line.

     

     

    It's a free download on DevCentral that you can get here:

     

    http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/1/aff/2085/afv/topicsview/showtab/groupforums/Default.aspx