Forum Discussion
jrosales2000_10
Nimbostratus
Dec 01, 2009Using Priorities in irules
Hi, i am trying to accomplish the following:
1) if user enters abc.com redirect to https://www.abc.com
2) if user enters www.abc.com redirect to https://www.abc.com
I am trying to use the following irule:
when HTTP_REQUEST priority 100 {
if { [HTTP::host] eq [domain [HTTP::host] 2] } {
HTTP::redirect "https://www.[HTTP::host]"
}
}
when HTTP_REQUEST priority 200 {
HTTP::redirect https://[HTTP::host][HTTP::uri]
}
But its not working. If user enters abc.com, user gets Page Cannot Be Displayed. if user enters www.abc.com it correctly redirects to https://www.abc.com.
I have tried breaking it out into 2 separate irules, applied in order 1 then 2.
Still, same result - abc.com gets page cannot be displayed, www.abc.com redirects properly to https://www.abc.com.
If i remove the priority 200 code completely, leaving
when HTTP_REQUEST priority 100 {
if { [HTTP::host] eq [domain [HTTP::host] 2] } {
HTTP::redirect "https://www.[HTTP::host]"
}
}
Then scenario 1 does work, so i know that that code is good. However, the 2 pieces together just will not work. Am i doing something wrong here?
Thanks,
Jodie
- hoolio
Cirrostratus
Hi Jodie,when HTTP_REQUEST { 1) if user enters abc.com redirect to https://www.abc.com 2) if user enters www.abc.com redirect to https://www.abc.com Check the requested host header value (set to lowercase) switch [string tolower [HTTP::host]] { "abc.com" - "www.abc.com" { Redirect client to https://www.abc.com/ HTTP::redirect "https://www.abc.com/" } default { Take some default action? } } }
- jrosales2000_10
Nimbostratus
That worked perfectly, thanks much!! - hoolio
Cirrostratus
Which HTTP traffic do you not want to redirect to HTTPS? Or what is the criteria for the traffic you *do* want to redirect to HTTPS? - jrosales2000_10
Nimbostratus
I want the following to scenarios to route to https://www.domainname.com - hoolio
Cirrostratus
Is there any traffic you don't want to redirect from http to https? You could check for host header values matching the patterns *.* or www.*.* and redirect those to https. But I'm still not clear on what if any traffic you want to allow via http. Is the logic dependent on the requested URI at all? - jrosales2000_10
Nimbostratus
hi, for the sites that have ssl, we don't wany any traffic going to http - we want all traffic routed to https. The logic is dependent on the requested URI. we would want abc.com and www.abc.com to redirect to https://www.abc.com. For another virtual server, we would want def.com and www.def.com to redirect to https://www.def.com. and so on... - hoolio
Cirrostratus
So you could redirect all requests to https://www.[base domain name]/ where the base domain name is whatever the client entered with www. added if it's not there already? If that sounds about right, I think this should work for your scenario:when HTTP_REQUEST { Check if host starts with www. if {[string tolower [HTTP::host]] starts_with "www."}{ Redirect client with same host and URI to https HTTP::redirect "https://[HTTP::host][HTTP::uri]" } else { Redirect client with www. prepended to host and same URI to https HTTP::redirect "https://www.[HTTP::host][HTTP::uri]" } }
- jrosales2000_10
Nimbostratus
Great, thanks! I'll be trying this out shortly.
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