Forum Discussion
Matt_Breedlove_
Nimbostratus
Aug 08, 2011assistance with literal question mark in switch
Hi All,
In this switch, it allows through a few URI prefixes with a wildcard, but then there is a URI that is like this
/?g
or like this
/?w
any single character following the literal question mark
Is this the right syntax to use? Thanks in advance
M
when HTTP_REQUEST {
switch -glob [URI::decode [string tolower [HTTP::uri]]] {
/ab* { return }
/cd* { return }
/ef* { return }
/\\?? { return }
default {
discard
}
}
discard
}
- Michael_Yates
Nimbostratus
You might have to find an alternate method that using a "?", since it is a Wildcard character. - hoolio
Cirrostratus
Michael's idea of using just the query string might work for your scenario. If not, you should be able to escape the question mark to have it interpreted literally. Here's a quick test using tclsh. I think you'd want just one backslash:% switch -glob {/z?} { "/ab*" - "/cd*" - "/\\??" { puts matched } default { puts "no match" } } no match % switch -glob {/z?} { "/ab*" - "/cd* - "/\??" { puts matched } default { puts "no match" } } matched
- Matt_Breedlove_
Nimbostratus
Would it be safer just to use - Michael_Yates
Nimbostratus
I tinkered with this again and got these working as expected.when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/foo*" { HTTP::redirect "http://www.yahoo.com" } "/\\?\\?*" { HTTP::redirect "http://www.msn.com" } "/\\?*" { HTTP::redirect "http://www.google.com" } } }
- hoolio
Cirrostratus
Michael, you were right. You need two backslashes to escape the question mark:% switch -glob {/yz} { "/ab*" - /cd* - "/\\??" { puts matched } default { puts "no match" } } no match % % switch -glob {/?z} { "/ab*" - /cd* - "/\\??" { puts matched } default { puts "no match" } } matched
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects