Forum Discussion

N__197982's avatar
N__197982
Icon for Nimbostratus rankNimbostratus
Jun 23, 2015

Understanding one of the iRules I found on the devcentral links.

Folks,

 

We came across an request from the applications team where they wanted a VIP listening on port 8080(http) to forward requests on port 443(https).

 

I checked the plain HTTP to HTTPS redirect but that would not work. What was happening is the a URL e.g. http://test.nik.com:8080 was being redirected to https://test.nik.com:8080 and that was not what was desired.

 

While searching for some hints I found the below iRule which worked, however I do not understand the logic.

 

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

 

Any help? :-)

 

Thanks, N.

 

1 Reply

  • To understand the irule, you must know how HTTP is parsed:

    for the URL : http://test.nik.com:8080/test.txt the request is

    GET /test.txt HTTP/1.1
    Host : test.nik.com:8080
    other headers
    

    in this request:

    • HTTP::uri is /test.txt
    • HTTP::host is test.nik.com:8080
    • [getfield [HTTP::host] ":" 1] is the first part of HTTP::host with field separator ":" --> test.nik.com

    this irule redirect to : https://test.nik.com/test.txt