Forum Discussion
Applying lowercase iRule to HTTPS virtual server?
Hi 1000blocks,
you may take a look to the two iRules below. Both iRules are using a very fast code path to identify the "good" requests (should be >90% of the total request).
In addition both iRules are not [string tolower] the entire [HTTP::uri] string, since this approach may break certain applications. Both iRules will therefor [string tolower] only the [HTTP::host] and/or [HTTP::path] information, while keeping possible [HTTP::query] information in the original case.
iRule1: If is the only sitename served by the virtual server.
when HTTP_REQUEST {
if { [string tolower "[HTTP::host][HTTP::path]"] equals "www.mysitename.com[HTTP::path]" } then {
Allow the request to pass. Should be >90% of the requests.
return
}
Wrong host or mixed case URL requested.
if { [HTTP::query] ne "" } then {
HTTP::respond 301 noserver Location "https://www.mysitename.com[string tolower [HTTP::path]]?[HTTP::query]"
} else {
HTTP::respond 301 noserver Location "https://www.mysitename.com[string tolower [HTTP::path]]"
}
}
iRule2: If multiple sitenames are served by the virtual server.
when HTTP_REQUEST {
switch -glob -- [string tolower [HTTP::host]] {
"www.mysitename.com" {
if { [string tolower [HTTP::path]] equals [HTTP::path] } then {
Allow the request to pass...
} else {
if { [HTTP::query] ne "" } then {
HTTP::respond 301 noserver Location "https://www.mysitename.com[string tolower [HTTP::path]]?[HTTP::query]"
} else {
HTTP::respond 301 noserver Location "https://www.mysitename.com[string tolower [HTTP::path]]"
}
}
}
"*mysitename.com*" {
if { [HTTP::query] ne "" } then {
HTTP::respond 301 noserver Location "https://www.mysitename.com[string tolower [HTTP::path]]?[HTTP::query]"
} else {
HTTP::respond 301 noserver Location "https://www.mysitename.com[string tolower [HTTP::path]]"
}
}
"www.mysitename2.com" {
if { [string tolower [HTTP::path]] equals [HTTP::path] } then {
Allow the request to pass...
} else {
if { [HTTP::query] ne "" } then {
HTTP::respond 301 noserver Location "https://www.mysitename2.com[string tolower [HTTP::path]]?[HTTP::query]"
} else {
HTTP::respond 301 noserver Location "https://www.mysitename2.com[string tolower [HTTP::path]]"
}
}
}
"*mysitename2.com*" {
if { [HTTP::query] ne "" } then {
HTTP::respond 301 noserver Location "https://www.mysitename2.com[string tolower [HTTP::path]]?[HTTP::query]"
} else {
HTTP::respond 301 noserver Location "https://www.mysitename2.com[string tolower [HTTP::path]]"
}
}
default {
Further/Unknown HOST-names...
}
}
}
Cheers, Kai
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