Forum Discussion

lchln_304378's avatar
lchln_304378
Icon for Nimbostratus rankNimbostratus
Jan 05, 2017

event disable HTTP rewrite

Hi guys,

Currently migrating a legacy web application using Apache over to F5. Unfortunately, due to the nature of the application there are specific rewrites that need to occur so it works. Due to the way the web application works, the clients connect on their individual subdomains, which are then identified and rewritten in the HTTP header which gets sent to the backend server. I am able to get the users to connect to the initial landing page, but after they submit their details rather than getting sent to the next page the iRule executes again and sends users back to the landing page instead.

How I want it to work:

Client sees: a.domain.com > iRule > Internal server sees: domain.com/test/a

Client enters details, submits and then sees: a.domain.com/post > iRule > Internal server sees: domain.com/test/a/post

I figured I could get this working by utilising the event disable command and apply a second iRule to the VS which executes when data meets the conditions for a.domain.com/post. This isn't working as I expected, below are the iRules I've configured:

    when HTTP_REQUEST {
set cust_id [getfield [HTTP::host] "." 1]
switch -glob [string tolower [HTTP::uri]]  {
            "*lib/*" {
                        HTTP::header "https://domain.com/lib/*"
            }
            "*static_pages/*" {
                        HTTP::header "https://domain.com/static_pages/*"
            }
            "*assets/*"  {
                         HTTP::header "https://domain.com/assets/*"
            }
            default {
        HTTP::header replace host [HTTP::host]
        HTTP::uri "/client/$cust_id"
         event disable 
        }
    }
}

That is the first rule, it will take users to a page where they enter their details, they'll then do a POST that is meant to take them to:

  when HTTP_REQUEST {
set cust_id [getfield [HTTP::host] "." 1]
switch -glob [string tolower [HTTP::uri]] {
            "*lib/*" {
                        HTTP::header "https://domain.com/lib/*"
            }
            "*static_pages/*" {
                        HTTP::header "https://domain.com/static_pages/*"
            }
            "*assets/*"  {
                         HTTP::header "https://domain.com/assets/*"
            }
            default {
        HTTP::header replace host [HTTP::host]
        HTTP::uri "/client/$cust_id/post"
        event disable
        }
    }
}

What I'm seeing is the first rule executing even after I've specified the event disable command. Any advice on how to tackle this one?

2 Replies

  • May be I am overlooking something but on first glance, both your iRules look the same. If you are trying to make sure that the client sees "a.domain.com" but the server sees "domain.com", you need something like this:

    when HTTP_REQUEST {
    if { [HTTP::host] contains "a.domain.com" } {
    HTTP::host [string map {a.domain.com domain.com} [HTTP::host]] 
    pool POOL-DEV2
    }
    }
    
    when HTTP_RESPONSE {
    if { [HTTP::header values Location] contains "domain.com" } {
    HTTP::header replace Location [string map {domain.com a.domain.com} [HTTP::header value Location]]
    }
    }
    

    You can potentially include the HTTP::uri logic within the iRule to achieve your goal.

  • For anyone curious, figured out that I had to define at the end of the iRule:

     

    event disable all

     

    This seemed to have done the trick