Forum Discussion
redirecting L7 traffic
I'm trying to figure out how to redirect a set of L7 traffic host headers. Here's what I'd like to do:
redirect http://test.me.com to https://test.me.com, but all other traffic (example, johnny.test.com) should stay with http. any assistance would be greatly appreciated.
14 Replies
- VFB
Cirrus
Eventually, I'd be adding johnny.test.com to redirect as well, but at this moment, it should remain http. How would I add it down the road to the same iRule? - Cory_50405
Noctilucent
Try this:
when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "test.me.com" } { HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri] } }- VFB
Cirrus
Thanks much! How would I modify the iRule to add more urls to reredirected to https and let's say pool1 instead of pool2?
- Cory_50405
Noctilucent
To do pool selection based on host, try something like this:
when HTTP_REQUEST { switch -glob [HTTP::host] { "www.company.com" - "www.company3.com" - "foo.company.com" - "bar.company.com" - { pool mypool1 } default { pool mypool2 } } }- VFB
Cirrus
thanks for your help thus far. you have the switch -glob part in there but you left out rewriting them to https (www.company.com - bar.company.com) - Cory_50405
Noctilucent
Apologies, thought you were looking to direct to a pool based on hostname. To use a switch to redirect, just replace 'pool mypool1' with 'HTTP::redirect "https://test.me.com"
- Moe_Jartin
Cirrus
Additionally, add the "string tolower" on the switch statement so that these will match even if the user enters the host name in all caps or something.
switch -glob [string tolower [HTTP::host]]
Joe
- Cory_50405
Noctilucent
Good catch. - VFB
Cirrus
Does this look correct? when HTTP_REQUEST { switch -glob [HTTP::host] { "www.company.com" - "www.company3.com" - "foo.company.com" - "bar.company.com" - { HTTP::redirect "https://$host/" pool mypool1 } default { pool mypool2 } } } - VFB
Cirrus
forgot the case sensitive piece when HTTP_REQUEST { switch -glob [string tolower [HTTP::host]]{ "www.company.com" - "www.company3.com" - "foo.company.com" - "bar.company.com" - { HTTP::redirect "https://$host/" pool mypool1 } default { pool mypool2 } } }
- Moe_Jartin
Cirrus
Close. If all non-redirected traffic goes to the same pool then just let this be the redirect irule.
when HTTP_REQUEST { switch -glob [string tolower [HTTP::host]]{ "www.company.com" - "www.company3.com" - "foo.company.com" - "bar.company.com" - { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } } }Joe
- VFB
Cirrus
that's the thing - it doesn't. http traffic goes to 1 pool and https traffic goes to another pool.
- Moe_Jartin
Cirrus
These should probably be different VIPs anyway. An HTTP VIP pointing to the HTTP pool. This HTTP VIP will have this iRule tied to it to redirect as needed.
Then a HTTPS VIP pointing to the HTTPS pool.
Joe
- VFB
Cirrus
I tested the following on my VMWARE simulator and it worked. Just wanted to see if it would work in a real life environment - when HTTP_REQUEST { switch -glob { [string tolower [HTTP::host]] } { "test.me.com" - "yahoo.com" - [HTTP::redirect https://$host/] } }
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