Forum Discussion
Lowercase URI
Below I have the current rule setup: when HTTP_REQUEST {
Check for capital letters in string if {[string match {[A-Z]} [HTTP::path]]}{
HTTP::redirect "http://[HTTP::host][string tolower [HTTP::path]][HTTP::query]"
} }
This is working and converting the string to all lowercase. I want the rule to only do pages or strings that end in .aspx?
Can this be done
47 Replies
- Cory_50405
Noctilucent
Try this one:
when HTTP_REQUEST { if { (string match {A-Z} [HTTP::uri]) and ([HTTP::path] ends_with ".aspx")} { set hostname [string tolower [HTTP::host]] set uriname [string tolower [HTTP::uri]] log local0. "Request is $hostname$uriname" HTTP::redirect "http://$hostname$uriname" } } - cjones_01_13155
Nimbostratus
01070151:3: Rule [/Common/Set_lowercase2] error: line 2: [parse error: PARSE syntax 34 {syntax error in expression " (string match {A-Z} [HTTP::uri]) and ([HTTP::path] ends_wit...": variable references require preceding $}] [{ (string match {A-Z} [HTTP::uri]) and ([HTTP::path] ends_with ".aspx")}]
- Cory_50405
Noctilucent
Bad formatting on my part:
when HTTP_REQUEST { if { [string match {[A-Z]} [HTTP::uri]] and ([HTTP::path] ends_with ".aspx")} { set hostname [string tolower [HTTP::host]] set uriname [string tolower [HTTP::uri]] log local0. "Request is $hostname$uriname" HTTP::redirect "http://$hostname$uriname" } } - cjones_01_13155
Nimbostratus
Same result. It isnt redirecting any part of the url to lowercase.
- Cory_50405
Noctilucent
Let's try nested if statements, with logging. This preserves your original check which you say was working:
when HTTP_REQUEST { if { [string match {[A-Z]} [HTTP::uri]] } { log local0. "Capital letter found in URI" if { [HTTP::path] ends_with ".aspx" } { set hostname [string tolower [HTTP::host]] set uriname [string tolower [HTTP::uri]] log local0. "Request is $hostname$uriname" HTTP::redirect "http://$hostname$uriname" } } }What gets logged to /var/log/ltm when you attempt a connection using this iRule and an FQDN of http://stg.sp10.shrm.org/LegalIssues/EmploymentLawAreas/Pages/default.aspx?
- cjones_01_13155
Nimbostratus
Im not seeing anything in the logs related to that Irule.
- Cory_50405
Noctilucent
Are you certain the FQDN you are using to test with is resolving to the virtual server IP address that you have this iRule applied to? The iRule is now using your original logic which you said was working (simply matching an uppercase letter). If that were the case, then you should at least be seeing the "Capital letter found in URI" message in your LTM log.
- cjones_01_13155
Nimbostratus
Yes Im sure. The only Irule I ever actually had working was the one posted at the very top of this thread
hen HTTP_REQUEST {
Check for capital letters in string if {[string match {[A-Z]} [HTTP::path]]}{HTTP::redirect "http://[HTTP::host][string tolower [HTTP::path]][HTTP::query]" } }
- Cory_50405
Noctilucent
Okay, so path instead of uri was used in your original iRule. Can't imagine that would make a difference, but...
when HTTP_REQUEST { if { [string match {[A-Z]} [HTTP::path]] } { log local0. "Capital letter found in URI" if { [HTTP::path] ends_with ".aspx" } { set hostname [string tolower [HTTP::host]] set uriname [string tolower [HTTP::uri]] log local0. "Request is $hostname$uriname" HTTP::redirect "http://$hostname$uriname" } } } - cjones_01_13155
Nimbostratus
I dont see anything in the Logs. I do see it execute under the local traffic stats.
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