Forum Discussion

Anush's avatar
Anush
Icon for Nimbostratus rankNimbostratus
Mar 02, 2015

Data group "/" definition

Hi Experts,

 

Thanks in advance for your time and respond to this question.

 

I have request to redirect couple of URLs to specific site.

 

https://abc.com/ or https://abc.com/uri1 or https://abc.com/uri2 then redirect to https://def.com otherwise redirect to pool members

 

I decided to use data-group to list out all URLs in one data group and reference that data group in irule. one thing I am not sure about it how F5 would understand for https://abc.com/ in the list.

 

Does it take just as a host URL or host with any URIs? because client only want to redirect specified URIs to the def.com, everything else would be redirect to pool members?

 

Thanks

 

13 Replies

    • Anush's avatar
      Anush
      Icon for Nimbostratus rankNimbostratus
      Thanks for your reply. so if I have following list in data group / := /uri1 := /uri2 := Does the first line take as https://abc.com or https://abc.com includes any URI after that? Thanks
    • Anush's avatar
      Anush
      Icon for Nimbostratus rankNimbostratus
      Thanks for your reply. so if I have following list in data group / := /uri1 := /uri2 := Does the first line take as https://abc.com or https://abc.com includes any URI after that? Thanks
  • I think you're best bet if you want to use a data group would be to put the source host and uri as the name and then the redirect host (& uri) as the value. Then, in your irule you would just use the class command to search the datagroup for the host and uri. Something like this might work. (Note: it will ignore your protocol, so you'd only be checking on

    abc.com
    instead of
    http://abc.com
    . Need to be sure you enter the data group items in based on that.)

    when HTTP_REQUEST {
        set key [string tolower "[HTTP::host][HTTP::uri]"]
    
        if { [class match $key equals DATA_GROUP_NAME] } {
            HTTP::respond 302 [class match -value $key equals DATA_GROUP_NAME]
            return
        }
    }
    
  • The

    HTTP::host
    command will only give the host name ("abc.com"). It won't give your the protocol. So you don't want to use that when you're comparing because it'll never be equal.

    Your iRule's logic will work as long as you want any host that has one of the uris specified in the data group to be redirected to def.com. That means that

    https://abc.com/uri1
    would go to
    https://def.com
    , as well as
    https://def.com/uri1
    would be redirected as well.

    Are you trying to redirect everything with a specific URI to def.com, or only certain hosts like abc.com?

  • give this a try:

    when HTTP_REQUEST {
        if { [string tolower [HTTP::host]] equals "abc.com" && [HTTP::uri] equals "/" } {
            HTTP::redirect "https://def.com"
        }
        elseif { [class match [string tolower [HTTP::uri]] starts_with "/Common/URL_REDIRECT"] } {
            HTTP::redirect "https://def.com"
        }
        else {
            pool POOL_NAME
        }
    }
    
    • Anush's avatar
      Anush
      Icon for Nimbostratus rankNimbostratus
      Thanks Brad. One last question. I am using GUI to add list of URIs in data group /uri1 := /uri2 := is this the correct syntax? Thanks
  • give this a try:

    when HTTP_REQUEST {
        if { [string tolower [HTTP::host]] equals "abc.com" && [HTTP::uri] equals "/" } {
            HTTP::redirect "https://def.com"
        }
        elseif { [class match [string tolower [HTTP::uri]] starts_with "/Common/URL_REDIRECT"] } {
            HTTP::redirect "https://def.com"
        }
        else {
            pool POOL_NAME
        }
    }
    
    • Anush's avatar
      Anush
      Icon for Nimbostratus rankNimbostratus
      Thanks Brad. One last question. I am using GUI to add list of URIs in data group /uri1 := /uri2 := is this the correct syntax? Thanks
  • Anush's avatar
    Anush
    Icon for Nimbostratus rankNimbostratus

    Hi Brad,

     

    I made little modification in the script and works just fine..

     

    when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "abc.com" && [HTTP::uri] equals "/" } { HTTP::redirect "https://def.com" } elseif { [class search URL_REDIRECT starts_with [HTTP::uri]] } { HTTP::redirect "https://def.com" } else { pool POOL_NAME } }

     

    Thanks