Forum Discussion

SP_266134's avatar
SP_266134
Icon for Nimbostratus rankNimbostratus
Jan 23, 2019

redirect http requests to https

Hi Guys, I have a two vips one is at 443 and another one dummy vip with same address at port 80 for http traffic. when users go to all works fine. with other vip if user goes http://domain.com, it is redirecting to https but SSL are lost. here is the Irule when HTTP_REQUEST {

 

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

 

in order to solve this issues I am planning to add add "www" like this in the below script. As I dont have test environment setup i want to confirm with some experts before i try. Any suggestion are also welcome.

 

when HTTP_REQUEST { HTTP::redirect ".[HTTP::host][HTTP::uri]" } }

 

  • There is actually an iRule built into BIG-IP for that purpose.

     

    HERE is actually a DevCentral article on it with some good info in the comments.

     

    Hope that helps! If it does please up-vote and select this answer, it'd be greatly appreciated!

     

    -Dylan

     

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    Try this one:

    when HTTP_REQUEST { 
        if { not ([string tolower [HTTP::host]] starts_with "www.") } {
            HTTP::redirect "https://www.[HTTP::host][HTTP::uri]"
        } else {
            HTTP::redirect "https://[HTTP::host][HTTP::uri]"    
        } 
    } 
    

    .

  • Hi SP,

    if is the only web application on the IP, then simply redirect to a fixed HOST-value. It will work in any case...

    when HTTP_REQUEST {
        HTTP::respond 301 "Location" "https://www.domain.com[HTTP::uri]"
         HTTP::respond 302 "Location" "https://www.domain.com[HTTP::uri]"
    }
    

    Note: If you don't use HTTP to access your web site and also not plan to use it in the future, then it would be far more elegant to send a 301 (Permanent Redirect) instead of 302 (Temporary Redirect) response. The

    HTTP::redirect
    command can only send 301 (Temporary Redirect) responses, but the
    HTTP::respond
    command can either send a
    301
    or
    302
    redirect response (see example above).

    Cheers, Kai