Forum Discussion
iRule Question - https to https://www
Currently I have an iRule in place that does uses switch to do a web site redirect and a http to https redirect on a http VIP, see below.
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::host]] {
"abc.com" -
"www.abc.com" {
HTTP::redirect http://abc.123.com
}
"def.com" -
"www.def.com" {
HTTP::redirect https://www.def.com[HTTP::uri]
}
default {
reject
}
}
}
Now, I like to also implement a similar redirect on the https VIP. Basically, I need to redirect https://def.com to https://www.def.com. Could I use something similar to the above?
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::host]] {
"def.com" -
"www.def.com" {
HTTP::redirect https://www.def.com[HTTP::uri]
}
default {
reject
}
}
}
Or, should I use the below, which I found on another post?
when HTTP_REQUEST {
if { !([HTTP::host] starts_with "www.") &&
([HTTP::host] contains "hostname.net") ) {
HTTP::redirect "https://www.[HTTP::host][HTTP::uri]"
}
}
Any suggestions would be helpful? The main thing is that the iRules would not conflict with one another, which I don't think would be the case since they are for different VIPs.
1 Reply
Hello,
The irule that use a switch will cause a loop when doing requests with www.def.com hostname
I suggest this :
when HTTP_REQUEST { switch -glob [string tolower [HTTP::host]] { "def.com" { HTTP::redirect https://www.def.com[HTTP::uri] } "www.def.com" { do nothing } default { reject } } }
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
