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

rct101's avatar
rct101
Icon for Nimbostratus rankNimbostratus
Dec 19, 2024

iRule - Url rewrite and header replace and pool selection not working

I have a scenario where I need to perform a header replace and url rewrite and select a pool.

I have several sites that I need to select a specific pool and they all have to come through the same

virtual server.

When I select a pool the content returned is not complete. The web page is missing formatting and content.

If I define a default pool that would be used for the specific site the content returned is complete for that site

but still missing content for the other sites not using a default pool.

I have tried a /32 oneconnet profile and that made no difference.

Below is my irule

when HTTP_REQUEST {
   switch -glob [string tolower [HTTP::host]] {
         "mywebsite.test.edu" {
            switch -glob [string tolower [HTTP::uri]] {
             "/mytestsite1" { HTTP::redirect "https://mywebsite.test.edu/mytestsite1/Authentication/Login?" }
             "/mytestsite1/*" {if {[HTTP::host] ne ""} {
                            HTTP::header replace Host "differentname.test.edu"
                            HTTP::uri [string map -nocase {"/mytestsite1/" "/differentname1/"} [HTTP::uri]] }
                            pool mypool1
                            return
                            }
             "/mytestsite2" { HTTP::redirect "https://mywebsite.test.edu/mytestsite2/Authentication/Login?" }
             "/mytestsite2/*" { if {[HTTP::host] ne ""} {
                            HTTP::header replace Host "differentname.test.edu"
                            HTTP::uri [string map -nocase {"/mytestsite2/" "/differentname2/"} [HTTP::uri]] }
                            pool mypool2
                            return
                            }
             "/mytestsite3" { HTTP::redirect "https://mywebsite.test.edu/mytestsite3/Authentication/Login?" }
             "/mytestsite3/*" { if {[HTTP::host] ne ""} {
                            HTTP::header replace Host "differentname.test.edu"
                            HTTP::uri [string map -nocase {"/mytestsite3/" "/differentname3/"} [HTTP::uri]] }
                            pool mypool3
                            return
                            }
                    
        }
      }
    }
 }

 

 

5 Replies

  • HTTP::host may contain port number, e.g. aaa.bbb.ccc:8888.
    so you need to remove the port number.

     

  • Hi rct101

    Can you try below one and let me know if it works ?

     

    when HTTP_REQUEST {
        switch -glob [string tolower [HTTP::host]] {
            "mywebsite.test.edu" {
                switch -glob [string tolower [HTTP::uri]] {
                    "/mytestsite1" {
                        HTTP::redirect "https://mywebsite.test.edu/mytestsite1/Authentication/Login?"
                    }
                    "/mytestsite1/*" {
                        if {[HTTP::host] ne ""} {
                            HTTP::header replace Host "differentname.test.edu"
                            HTTP::uri [string map -nocase {"/mytestsite1/" "/differentname1/"} [HTTP::uri]]
                        }
                        pool mypool1
                        return
                    }
                    "/mytestsite2" {
                        HTTP::redirect "https://mywebsite.test.edu/mytestsite2/Authentication/Login?"
                    }
                    "/mytestsite2/*" {
                        if {[HTTP::host] ne ""} {
                            HTTP::header replace Host "differentname.test.edu"
                            HTTP::uri [string map -nocase {"/mytestsite2/" "/differentname2/"} [HTTP::uri]]
                        }
                        pool mypool2
                        return
                    }
                    "/mytestsite3" {
                        HTTP::redirect "https://mywebsite.test.edu/mytestsite3/Authentication/Login?"
                    }
                    "/mytestsite3/*" {
                        if {[HTTP::host] ne ""} {
                            HTTP::header replace Host "differentname.test.edu"
                            HTTP::uri [string map -nocase {"/mytestsite3/" "/differentname3/"} [HTTP::uri]]
                        }
                        pool mypool3
                        return
                    }
                }
            }
        }
    }

    • rct101's avatar
      rct101
      Icon for Nimbostratus rankNimbostratus

      This just looks like formatting of the code layout. Went ahead and tried it but no difference.