Forum Discussion

coriolis_75734's avatar
coriolis_75734
Icon for Nimbostratus rankNimbostratus
Feb 04, 2014

Redirect based on datagroup

I have an iRule which checks to see if the URI is listed within a datagroup and then does a redirect to the value for that URI within the datagroup.

Now the customer would like it to check for the URI plus a trailing / (e.g. /redirectme/ as well as /redirectme ) but the data group list only contains the URI's without the trailing /. The data group has hundreds of entries so adding all the URI's again including the / is out of the question. My iRule is currently:

if { [class match [HTTP::uri] eq datagroup_uri_list] } {
        HTTP::respond 302 Location "[class match -value [HTTP::uri] eq datagroup_uri_list]"
} 

What would be the best way to add a / to the end of the datagroup_uri_list entries so they can be compared to the URI?

I assume it'll be something like:

if { [(class match [HTTP::uri] eq datagroup_uri_list] || class match [HTTP::uri] eq datagroup_uri_list]+/  } {
        HTTP::respond 302 Location "[class match -value [HTTP::uri] eq datagroup_uri_list]"
} 

3 Replies

  • Just curious here, but wouldn't it be much simpler to just use a "starts_with" condition to cover a trailing slash and anything that may come after the request URI?

     

  • Unfortunately not as it's very likely that would cause it to incorrectly match pages.

     

    The redirect for /page/site would trigger for /page/site/sub_page/ etc and each one has a different destination.

     

    Each entry in the data group is for a specific page on an old website which then redirects to its new location on their new portal.

     

  • Think I've figured this out now. I used trimright to remove the trailing / before the datagroup comparison.

    if {([class match [string trimright [HTTP::path] "/" ] eq datagroup_uri]) } { 
        HTTP::respond 302 Location "[class match -value [string trimright [HTTP::path] "/" ] eq datagroup_uri]"
    }