Forum Discussion
url check starts_with number to avoid looping
Hello, Below is my iRule that redirects an incoming url to a versioned url, by using the verison number in the header. In order to avoid infinite looping I am looking for a way to check "uri does not start_with number". Can you please suggest a way to do that? when HTTP_REQUEST { if { [HTTP::host] eq "xservicesdev.abc.com" and \ [matchclass [HTTP::uri] starts_with $::xservicesuri] and \ [HTTP::header exists Authorization] and \ [HTTP::header exists Version] } { HTTP::redirect "http://[HTTP::host]/[HTTP::header Version][HTTP::uri]" } } This line - [matchclass [HTTP::uri] starts_with $::xservicesuri] checks if the uri starts with some specific service domains (xservicesuri is a list of those names) to avoid looping. But this will also require change to the iRule everytime I have new domains. In order to avoid this I would like to check for the uri to "not start with" a version, so something like - not [matchclass [HTTP::uri] starts_with [HTTP::header Version]] but that didnt work. I tried both below: not [matchclass [HTTP::uri] starts_with $::xservicesuri] [matchclass [HTTP::uri] not starts_with $::xservicesuri] Would appreciate any suggestions. Thank you.
4 Replies
- What_Lies_Bene1
Cirrostratus
I would have thought this would work;if { not [HTTP::uri] starts_with [HTTP::header value Version] } { ...
Also note, you don't need to use $:: with your Class names. - Nams_119859
Nimbostratus
Thank you for the quick response. This is what I have now. But I get a connection reset when I try any url with "not". Without "not" it works but doesnt do what I need it to. Could it be that my F5 version (9.3.1) doesnt support "not"?
when HTTP_REQUEST {
if { not [HTTP::uri] starts_with "/[HTTP::header value Version]" and \
[HTTP::header exists Version] } {
HTTP::redirect "http://[HTTP::host]/[HTTP::header Version][HTTP::uri]"
}
} - Kevin_Stewart
Employee
The not operator is definitely supported in 9.x and above - it's a native construct of the TCL language.
I'd try something like this instead:when HTTP_REQUEST { if { ( [HTTP::header exists Version] ) and not ( [HTTP::uri] starts_with "/[HTTP::header Version]" ) } { HTTP::respond 302 Location "http://[HTTP::host]/[HTTP::header Version][HTTP::uri]" } }
Your if conditional should start with the exists clause before trying to look for its value. - Nams_119859
Nimbostratus
Thanks so much Kevin! That worked just fine.
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