Forum Discussion

Viversector_326's avatar
Viversector_326
Icon for Nimbostratus rankNimbostratus
Jul 05, 2017

Remove port number from URL

Hello,

 

I have a VIP running on port 443 which connects to our back end web servers running port 80. I have the following irule setup to change URLs from http to https. The problem I have is some of the URLs in the pages have port 80 appended to the end of them. Does anyone know how I can stop this from occurring?

 

For example, when I inspect the page when it's loaded via the VIP I see some URLs point to https://domain.com:80/style.css when it should be https://domain.com/style.css

 

Irule is below

 

when HTTP_REQUEST {

 

STREAM::disable HTTP::header remove "Accept-Encoding" } when HTTP_RESPONSE {

 

if {[HTTP::header value Content-Type] contains "text"}{ STREAM::expression {@@} STREAM::enable

 

}

 

}

 

11 Replies

  • f51's avatar
    f51
    Icon for Cirrostratus rankCirrostratus

    Create VIP on 443 and backend servers on port 80. Use the HTTP profile as http. So that it will translate the port number and we no need to give the port number.

     

    • Viversector_326's avatar
      Viversector_326
      Icon for Nimbostratus rankNimbostratus

      Hello,

       

      When I do that and I remove the irule, I am getting mix content warnings, some of the urls in the page are going over http not https. What do I need to do to fix the urls that are still coming as http?

       

      Thanks in advance

       

    • nag_54823's avatar
      nag_54823
      Icon for Cirrostratus rankCirrostratus

      Hello,

       

      This need to be change on code level. It should not call with :port when we call sublinks or another application. We just need to use either http or https.

       

    • f51's avatar
      f51
      Icon for Cirrostratus rankCirrostratus

      Hello,

       

      Then you can use http profile and check port translation enabled or not.

       

  • Create VIP on 443 and backend servers on port 80. Use the HTTP profile as http. So that it will translate the port number and we no need to give the port number.

     

    • Viversector_326's avatar
      Viversector_326
      Icon for Nimbostratus rankNimbostratus

      Hello,

       

      When I do that and I remove the irule, I am getting mix content warnings, some of the urls in the page are going over http not https. What do I need to do to fix the urls that are still coming as http?

       

      Thanks in advance

       

    • nag_54823's avatar
      nag_54823
      Icon for Cirrostratus rankCirrostratus

      Hello,

       

      This need to be change on code level. It should not call with :port when we call sublinks or another application. We just need to use either http or https.

       

    • f5_214411's avatar
      f5_214411
      Icon for Nimbostratus rankNimbostratus

      Hello,

       

      Then you can use http profile and check port translation enabled or not.

       

  • f51's avatar
    f51
    Icon for Cirrostratus rankCirrostratus

    Add http2https redirect irule and I am sure you it will works.

     

  • Hello Viversectors,

    You have two options :

    1) The proper manner is to do it from the backend servers by modifying absolute links by relative links:

    Relative links looks like /toto/tata

    Absolute links are similar to

    2) If you cannot change it or ask for that, you can modify your irule to modify also the domain.com:80 by domain.com and the Location header if contains http://

    when HTTP_REQUEST {
     STREAM::disable 
    
     if { [HTTP::header exists "Accept-Encoding"] } {
        HTTP::header remove "Accept-Encoding" 
     }
    
     if { [HTTP::header exists "Location"] } {
        set Location [HTTP::header Location]
        if { $Location contains "http://"} {
           HTTP::header replace Location [string map {"http://" "https://"} [HTTP::header Location]]
        }
     }
    
    }
    
    when HTTP_RESPONSE {
    
    if {[HTTP::header value Content-Type] contains "text" || [HTTP::header value Content-Type] contains "xml"  } {
      Replace http:// with https:// and domain.com:80 by domain.com 
     STREAM::expression [list {@http://@https://@} {@domain.com:80@domain.com@}]
      Enable the stream filter for this response only
     STREAM::enable
     }
    
    }
    

    I think with this irule you will cover all your need.

    Waiting for your update.

    Regards

  • Hi,

     

    you can try this code:

     

    when HTTP_REQUEST {
        STREAM::disable 
        if { [HTTP::header exists "Accept-Encoding"] } {
           HTTP::header remove "Accept-Encoding" 
        }
        set host [HTTP::host]
    }
    when HTTP_REQUEST_RELEASE {
        if {![info exists streamfilter]} {
            this part create the stream filter to convert absolute URL to relative URL if it is on the same web service.
             Must be done in client side (event HTTP_REQUEST_RELEASE) to get the pool member port number.
            set port [TCP::remote_port]
            set streamfilter [list "@http://${host}/@/@ @http://${host}:${port}/@/@"]
        }
    }
    
    when HTTP_RESPONSE {
    if { [HTTP::header exists "Location"] } {
        if { [set Location [HTTP::header Location]] starts_with "http://"} {HTTP::header replace Location [string map $streamfilter $Location]}
     }
    
    if {[HTTP::header value Content-Type] contains "text" || [HTTP::header value Content-Type] contains "xml"  } {
      apply stream filter
     STREAM::expression $streamfilter
      Enable the stream filter for this response only
     STREAM::enable
     }
    }