Forum Discussion
using regex with if condition and ends_with
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?
4 Replies
- Eric_St__John
Employee
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 } } - jaked_150553
Nimbostratus
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.
- Eric_St__John
Employee
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.
- jaked_150553
Nimbostratus
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?
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com