For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

david0512_20548's avatar
david0512_20548
Icon for Nimbostratus rankNimbostratus
Nov 11, 2014

http rewrite irule -- help!!

We have a requirement for a http rewrite but its driving me mad (as a newbie to irules and even after trawling through forums and docs) trying to get this right, and its been going on for weeks.

Customer Requirement:

1) browse to intially to http site.

2) This gets changed to HTTPS

3) HTTPs request is made by client to same location

4) Browser of client stays as www.abc.com/t/www/zzz but on the middleman (F5) host is rewritten to www.xyz.com (so client doesnt receive 302 redirect but instead receives 200 ok). The 200 response will actually come from this location (https://www.xyz.com/www.abc.com/t/www/zzz) but the URL in the user browser will still remain as https://www.abc.com/t/www/zzz

For example

GET http://www.abc.com/t/www/zzz HTTP/1.1 Host: www.abc.com

HTTP/1.0 301 Moved Permanently location: https://www.abc.com/t/www/zzz

CONNECT https://www.abc.com/t/www/zzz HTTP/1.1 HTTP/1.1 200 Connection Established

so on the Virtual server we have the following

iRule on HTTP VS: (initial http request)

    when HTTP_REQUEST {
    if { [HTTP::host] contains "www.abc." and [HTTP::uri] starts_with "/t/" } {
    HTTP::respond 301 location "https://[HTTP::host][HTTP::uri]"
     }
    }

Then iRule on HTTPS VS: (Https request)

    when HTTP_REQUEST {
    if { [HTTP::header host] contains "www.abc." and [HTTP::uri] starts_with "/t/" } {
    HTTP::uri "/[HTTP::host][HTTP::uri]"
    HTTP::header replace host "www.xyz.com" 
     }
    }

I was hoping the replace command on the second iRule would be transparent to the end user but we always seem to be getting the 302.

Can you advise if this is possible doing it this way or is there another way I can achieve the above?

1 Reply

  • R_Eastman_13667's avatar
    R_Eastman_13667
    Historic F5 Account

    You need to use the HTTP_RESPONSE event on your HTTP VS. Alos add the HTTP_REQUEST to capture the URI.

    when HTTP_REQUEST {
        set uri [HTTP::uri]
    }
    when HTTP_RESPONSE {
        if {[HTTP::is_redirect] && [HTTP::header value "Location"] contains "www.abc." && $uri starts_with "/t/"} {
            HTTP::header replace Location [string map {www.abc. "www.xyz.com"} [HTTP::header value Location]]
        }
    }