Forum Discussion

Phil_102636's avatar
Phil_102636
Icon for Nimbostratus rankNimbostratus
Oct 05, 2012

need help to get uri to work regardless of any extra characters

I have an irule that uses a data class to look for a keyword and if found redirects to another URL.

 

This part works fine but if for some reason any extra characters are put into the URL it fails.

 

For instance https://www.someplace.com/test would redirect to https://www.someotherplace.com

 

But if for any reason someone types in testy or anything besides /testyingiti etc it fails.

 

I've tried using starts_with but no dice. Would anyone know a method to redirect IF any part of test is in the word?

 

Thanks for any assistance.

 

7 Replies

  • I've tried using starts_with but no dice. just wondering why starts_with did not work. anyway, contains which Beneath suggested should work.
  • I confirmed "starts_with" in my irule calling a uri from a data class was working if any other characters were added, it just did not work correctly and/or broke with no redirect. Why? I really am at a loss. "Contains" also does not work, so it must be the nature of how the irule was written. Below is the key ingrediants so anyone can spot something, have at it.

     

     

    when HTTP_REQUEST {

     

    set my_uri [string trimright [HTTP::uri] "/" ]

     

    Determine if you are trying to go to a site that has a vanity URL

     

    if {[class match [string tolower [HTTP::uri]] contains www_vanity_url_redirection]}{

     

    set vanity_path [class search -value www_vanity_url_redirection starts_with [string tolower [HTTP::uri]]]

     

    HTTP::redirect $vanity_path

     

    } else {

     

    Do nothing

     

    unset set my_uri

     

    }

     

    }

     

     

  • what about this one?

    [root@ve10:Active] config  b virtual bar list
    virtual bar {
       snat automap
       pool foo
       destination 172.28.19.79:443
       ip protocol 6
       rules myrule
       profiles {
          clientssl {
             clientside
          }
          http {}
          tcp {}
       }
    }
    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       set my_uri [string tolower [HTTP::uri]]
       if {[class match -- $my_uri contains www_vanity_url_redirection]} {
          set vanity_path [class match -value $my_uri contains www_vanity_url_redirection]
          HTTP::redirect $vanity_path
       }
    }
    }
    [root@ve10:Active] config  b class www_vanity_url_redirection list
    class www_vanity_url_redirection {
       "/test" { "https://www.someotherplace.com" }
    }
    
    [root@ve10:Active] config  curl -Ik https://172.28.19.79/test
    HTTP/1.0 302 Found
    Location: https://www.someotherplace.com
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve10:Active] config  curl -Ik https://172.28.19.79/testy
    HTTP/1.0 302 Found
    Location: https://www.someotherplace.com
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    
  • YES!!!! I really appreciate your input and help! Even several other experienced F5 people I knew could not figure this one out!
  • There is one issue that remains. There is a potion above this irule that detects a mobile phone and if it finds it in our Data Class it will use anothere Data Class for keywords and then redirect to our mobile site, so it will recieve optimized pages.

     

     

    The same issues seems to plague us, if someone puts in extra characters it fails.

     

    Following the logic you provided fixed the pc version but for some reason it does not work on the mobile issue.

     

    Below is what I use.

     

     

    when HTTP_REQUEST {

     

    Set variables to be used later

     

    set ckname "mobile"

     

    set ckvalue "mobileoptfalse"

     

    set cookie [format "%s=%s; path=/; domain=%s" $ckname $ckvalue ".someplace.com"]

     

    if { [HTTP::query] contains "skipmobiledetect=true"}{

     

    HTTP::respond 302 Location "https://www.someplace.com" "Set-Cookie" $cookie

     

    }

     

    unset ckname

     

    unset ckvalue

     

    unset cookie

     

    The above statement are so if the user clicks on to the full url site it will capture cookie and not send them back to the mobile site.

     

    set mobile_opt_uri [class match -value [string tolower [HTTP::uri]] starts_with mobile_phone_optimized_uri]

     

    set my_uri [string trimright [HTTP::uri] "/" ]

     

    set mobile_site "https://m.somemobileplace.com"

     

    set mobile_uri [class search -value mobile_phone_optimized_uri eq [string tolower $my_uri]]

     

    set query [class search -value mobile_phone_optimized_uri eq [string tolower $my_uri]]?[HTTP::query]

     

     

    Check for the existence of the cookie from the mobile site and that you are not attempting to go to a page that has been optimized for mobile OR that your URI is not empty

     

    if {([HTTP::cookie exists mobile]) and not ([class match [string tolower [HTTP::uri]] contains mobile_phone_optimized_uri])}{

     

     

    } elseif { not ([HTTP::uri] == "/") and not ([class match [string tolower [HTTP::uri]] contains mobile_phone_optimized_uri])}{

     

     

    } else {

     

     

    Check the User Agent string for a supported Browser in the class "Mobile_Device_Provider"

     

    if {[class match [string tolower [HTTP::header User-Agent]] contains mobile_device_providers]}{

     

    Check the URI for a mobile optimized URI as defined in the class "mobile_phone_optimized_uri"

     

    if {[class match [string tolower [HTTP::uri]] contains mobile_phone_optimized_uri]} {

     

    Redirect to the appropriate site

     

    HTTP::redirect $mobile_site$my_uri

     

    } else {

     

    Redirect to the mobile root

     

    HTTP::redirect $mobile_site

     

    }

     

    }

     

    event disable

     

    }

     

     

     

     

    Below is there redirect for just pc computers using a uri keyword. And even if it has extra characters it will go to the supplied using the contains.

     

    This works fine.

     

     

    See full thread
  • set mobile_uri [class search -value mobile_phone_optimized_uri eq [string tolower $my_uri]]

     

    set query [class search -value mobile_phone_optimized_uri eq [string tolower $my_uri]]?[HTTP::query]i do not see mobile_uri and query is used anywhere in the code. anyway, just wonder whether it relates since it is using "equal".