Forum Discussion
iRule to redirect http and https to https over port 8888
I'm Definitely new to writing iRules. Trying to build one iRule to apply to 2 VIPs. One VIP listens on port 80 the other on port 443. The iRule would redirect any normal HTTP or HTTPS traffic to HTTPS on port 8888. Below is what I have right now, but it doesn't seem to work. Any help or advice would be greatly appreciated. Thanks.
when HTTP_REQUEST { if { [HTTP::uri] equals "; or [HTTP::uri] equals ";} { HTTP::redirect "; } }
Updated code with corrections...
when HTTP_REQUEST { if { [HTTP::host] equals "zzzzzz.xyz.com" or [HTTP::host] equals "zzzzzz.xyz.com"} { HTTP::redirect "https://zzzzzz.xyz.com:8888" } }What you want is..
when HTTP_REQUEST { switch [HTTP::host] { "xxxxxx.xyz.com" - "yyyyyy.xyz.com" - "zzzzzz.xyz.com" { HTTP::redirect https://[HTTP::host]:8888[HTTP::uri] } } }The "-" means use the action of the following condition. So all of the hosts listed will redirect to same hostname on port 8888.
6 Replies
- Sunny_291145
Nimbostratus
Try applying this
when HTTP_REQUEST {
HTTP::redirect "https://[getfield [HTTP::host] ":" 1]:8888[HTTP::uri]"}
- metagraphica_25
Nimbostratus
Thanks Sunny, looks like that worked.
- metagraphica_25
Nimbostratus
Hmm...actually it works fine for HTTP but not for the HTTPS redirect...
- Cory_O
Cirrostratus
Do you have SSL Client and HTTP profiles applied to your TCP/443 VIP? I know the HTTP Profile is required to read the HTTP traffic, but I'm pretty sure you'll need to decrypt it as well to be able to fire the HTTP_REQUEST Event. -Cory
- Kevin_Davies_40
Nacreous
Updated code with corrections...
when HTTP_REQUEST { if { [HTTP::host] equals "zzzzzz.xyz.com" or [HTTP::host] equals "zzzzzz.xyz.com"} { HTTP::redirect "https://zzzzzz.xyz.com:8888" } }What you want is..
when HTTP_REQUEST { switch [HTTP::host] { "xxxxxx.xyz.com" - "yyyyyy.xyz.com" - "zzzzzz.xyz.com" { HTTP::redirect https://[HTTP::host]:8888[HTTP::uri] } } }The "-" means use the action of the following condition. So all of the hosts listed will redirect to same hostname on port 8888.
- metagraphica_25
Nimbostratus
Cory O, yep I noticed that for some reason the https VIP didn't have the correct SSL client profile applied. Fixed than and now everything is working. Thanks.
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