I have requirement to check the end of a uri and check for pattern in it and take decisions based on it. example urls would be like this -
http://example.com/test/folder/dir-test http://example.com/test/folder/dir-test.xml http://example.com/test/folder/dir-test?varbs=123
how do i look for ‘-test’ at the end of the uri and redirect based on above mentioned urls? ‘test’ can be found in other parts of the uri also. switch can be used for regex but it doesn’t support ends_with, if condition supports but how to use regex in if condition? If yes how do i do it?
You shouldn’t need regex for the specific use case you outlined. The following will look at the HTTP path(No parameters), to match against a path that ends with “-test”.
when HTTP_REQUEST {
if { [HTTP::path] ends_with "-test" } {
do something
}
}
but what if there are other uris that end with -test.xml, -test.html or -test?params=21313 in these cased uri doesn’t end with -test alone, but with other stuff after -test.
What exactly do you want to be redirected, and what do you not want redirected? In your initial post you stated that you wanted to match against URIs that end with -test The iRule provided will do that. -test.html does not “end with” -test, it ends with -test.html When using [HTTP::path] the parameters are not evaluated, so -test?params=21313 would end up being evaluated as -test
If you can provide a clear example of what you do want to match and redirect for, it may be easier to provide a working example.
What you mentioned makes sense, what iam looking for is -test? if there is a lot of different variations after -test? in the uri how would I use regex with if condition?