Forum Discussion

Hamza_derbali's avatar
Hamza_derbali
Icon for Altostratus rankAltostratus
Oct 05, 2024

Rewriting Location Header in iRule

Hello everyone,

I'm trying to find a way to manipulate the HTTP::header location.

For each redirection containing a location header from the backend server, I need to rewrite just the host part of the URL following this rule:

If the location contains "http://webserver01:8282", the iRule should rewrite the host to "https://externallink.com" while preserving the rest of the URL.

For example:
http://webserver01:8282/login should be rewritten to https://externallink.com/login.

Any help to achieve this would be greatly appreciated.

Thanks!

  • Hi Hamza,

    when HTTP_RESPONSE {
        if { [HTTP::header Location] starts_with "http://webserver01:8282"} {
            HTTP::header replace Location [string map {"http://webserver01:8282" "https://externallink.com"} [HTTP::header Location]]
        }
    }
    

     

  • Hi Hamza,

    when HTTP_RESPONSE {
        if { [HTTP::header Location] starts_with "http://webserver01:8282"} {
            HTTP::header replace Location [string map {"http://webserver01:8282" "https://externallink.com"} [HTTP::header Location]]
        }
    }