Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

Datagroup Irule matching

I have been trying to make my code match for both host and uri. For example

  1. www.abc.com := www.xyz.com
  2. www.abc.com/def := www.example.com/dif

    when HTTP_REQUEST {
    set locationHttps [class match -value [HTTP::host] equals list-https]
    set locationHttp [class match -value [HTTP::host] equals list-http]
    
    if { $locationHttps ne ""} then {
        HTTP::respond 301 location "https://$locationHttps[HTTP::uri]"
        return
    }
    
    if { $locationHttp ne ""} then {
        HTTP::respond 301 location "http://$locationHttp[HTTP::uri]"
        return
    }  
    }
    

Right now the datagroup file uses:

"www.example.com" := "www.different.com",
"www.example.com/index.aspx" := "beta.example.com",
"www.interesting.com/en" := "app.example.com",

I noticed that everything behind the / either won't work or is taken with the url to the next one so I cannot hard edit behind the /. This was noticable when behind the /abcdef had to change into /abc-def

Is anyone able to help me along the right path to make URI work correctly?

I wasn't sure if I needed a new datagroup specific for the URI so I made one with the more common /en /index entries with empty ""

Every bit of help is welcome!

0
Rate this Question
Comments on this Question
Comment made 03-Jul-2017 by Andrew Husking 691

Based on your code above, only the first datagroup entry will work as you're trying to match [HTTP::host] against the datagroup. Because the next two have a URI in them as well, they will never match.

To do both, you'd need to do something like the below, but i don't have an F5 to test it on at the moment set locationHttps [class match -value [HTTP::host][HTTP::uri] equals list-https]

0
Comment made 03-Jul-2017 by ekaleido 711

And if you do this, remember that [HTTP::uri] will equal / in the absence of anything else.

0

Answers to this Question