Forum Discussion

atoth's avatar
atoth
Icon for Cirrus rankCirrus
Aug 14, 2020

Checking if a value exists in a data-group?

I've got an irule which doing 301 redirects. When a particular uri comes in, it checks the locale and matches it against a data-group with old locale in the uri being mapped to a new local.

 

For example "en_US" would map to "en-us" as the new value. It works fine for the most part, but if the locale that comes doesn't match a particular value in the data-group, it leaves the locale field blank in the 301 redirect. If the locale field in the uri contained something like /locale=en_ZZ, the redirect would just blank in the redirect.

 

Instead, we want it to redirect to a default page, and I'm not quite sure how to do that. First in the class match statement it would need to check if a matching value existed, but I'm not sure how to do that, and the class page on devcentral is a little confusing.

  • Hello atoth.

    Make the most of the command 'else':

    when HTTP_REQUEST {
    	if { [class match [HTTP::uri] equals "location_dg" ] } {
    		## DO YOUR STUFF
    	} else {
    		## DO YOUR STUFF IN CASE OF NOT MATCHING
    	}
    }

    Regards,

    Dario.

  • Hello atoth.

    Make the most of the command 'else':

    when HTTP_REQUEST {
    	if { [class match [HTTP::uri] equals "location_dg" ] } {
    		## DO YOUR STUFF
    	} else {
    		## DO YOUR STUFF IN CASE OF NOT MATCHING
    	}
    }

    Regards,

    Dario.