Forum Discussion

JosephT's avatar
JosephT
Icon for Nimbostratus rankNimbostratus
Jun 13, 2008

iRule redirect help

I have an irule that redirects all traffic to https:

 

 

rule https.redirect.irule {

 

when HTTP_REQUEST {

 

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

 

}

 

}

 

 

This works fine on a VIP listening on port 80 - all traffic is redirected to https.

 

 

I tried applying this to a vip listening on port 8004, but it is not working. Is this even possible?

2 Replies

  • It should as so long as it's http coming into a VIP on tcp port 8004.

     

     

    Since i wasn't sure what error you recieved, but you could verify by place a debug stastement into the code

     

      
      when HTTP_REQUEST {   
         HTTP::redirect "https://[HTTP::host][HTTP::uri]"  
         log local0. "Client [IP::client_addr] requested [HTTP::host][HTTP::uri]  
        }   
      }  
      

     

     

    when you test the redirect the "Client..." will be logged into the /var/log/ltm file on the LTM.

     

     

    hope this helps,

     

    CB

     

  • When testing with the VIP on port 8004, does the client make requests with the port number in the Host header? If so, you could remove it using the Codeshare example:

    http://devcentral.f5.com/Wiki/default.aspx/iRules/HTTPToHTTPSRedirect_302.html

     
     when HTTP_REQUEST { 
      
         Check if Host header value has a length 
        if {[string length [HTTP::host]]}{ 
      
            Redirect to the requested host and URI (minus the port if specified) 
           HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri] 
      
        } else { 
      
            Redirect to VIP's IP address 
           HTTP::redirect https://[IP::local_addr][HTTP::uri] 
        } 
     } 
     

    Aaron