Forum Discussion

Goldz_180077's avatar
Goldz_180077
Icon for Nimbostratus rankNimbostratus
Feb 04, 2019

http to https port 8080 redirection

Hi F5 Team,

 

can you validate my irules, if correct.

 

I need to redirect my http(80) access to https(8080)

 

Setup: VIP: 10.10.10.10 port 80 with redirection enable VIP: 10.10.10.10 port 8080 with SSL offload

 

i_Rules:

 

when HTTP_REQUEST { HTTP::redirect https://[getfield [HTTP::host] : 1]:8080[HTTP::uri] }

 

Regards,

 

Goldz

 

  • Hi Goldz,

    your iRule will do the trick.

    Personally I would prefer to use quotation marks to clearly define the start and end of embedded string values.

    when HTTP_REQUEST { 
        HTTP::redirect "https://[getfield [HTTP::host] ":" 1]:8080[HTTP::uri]" 
    }
    

    In addition you may check if a 301 "Permanent Redirect" would be suitable for your website, so that you save a round trip on subsequent HTTP requests.

    when HTTP_REQUEST { 
        HTTP::respond 301 "Location" "https://[getfield [HTTP::host] ":" 1]:8080[HTTP::uri]"
    }
    

    Also keep in mind, that sending a

    [HTTP::host]
    is only required for HTTP/1.1 requests. To support HTTP/1.0 requests, you may want to replace the
    [getfield [HTTP::host] ":" 1]
    syntax with a hardcoded string. You could also mix a dynamic redirect based on available
    [HTTP::host]
    values and use a hard coded string as a fall back by using a if-then-else syntax.

    when HTTP_REQUEST {
        if { [HTTP::host] ne "" } then {
            HTTP::respond 301 Location "https://[getfield [HTTP::host] ":" 1]:8080[HTTP::uri]"
        } else {
            HTTP::respond 301 Location "https://www.mysite.com:8080[HTTP::uri]"
        }
    }
    

    Cheers, Kai