Forum Discussion
Raj_57800
Nimbostratus
Nov 24, 2008iRule for Http redirect
I have defined a irule to forward http request to be converted as https. But when any https request to the same server is not being forwarded. This is the irule
when HTTP_REQUEST {
if {[TCP::local_port] == 80} {
HTTP::redirect https://xxx.com } {
else {
HTTP::fallback "https://xxx.com
}
}
Can anyone help me in finding the correct irule
raj
- hoolio
Cirrostratus
Hi Raj,when CLIENT_ACCEPTED { Check the requested port switch [TCP::local_port] { 80 { HTTP request, redirect to HTTPS using the same URI Check if Host header value has a length if {[string length [HTTP::host]]}{ Redirect to the requested host and URI (minus the port if specified) HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri] } else { Redirect to VIP's IP address HTTP::redirect https://[IP::local_addr][HTTP::uri] } } 443 { HTTPS request. Disable client SSL profile to prevent decryption SSL::disable } default { Request to undefined port. Take some default action? Send a reset? reject Drop the request? drop } } }
- Raj_57800
Nimbostratus
But why is that when my if statement is not true the traffic is not being diverted to a specific pool. - hoolio
Cirrostratus
What port is your VIP defined on? Does your VIP have a client and/or server SSL profile? Is the client making an HTTPS request? Is the server expecting SSL or non-SSL traffic? - Raj_57800
Nimbostratus
The VIP has a wildcard port enable(all ports) and there is no ssl enabled on it. The SSL is provided by the pool memeber. - Nicolas_Menant
Employee
when HTTP_REQUEST { if {[TCP::local_port] == 80} { HTTP::redirect https://xxx.com } { else { pool test_pool } }
when CLIENT_ACCEPTED { if {[TCP::local_port] == 443} { HTTP::disable pool test_pool } } when HTTP_REQUEST { if {[TCP::local_port] == 80} { HTTP::redirect https://xxx.com } }
- Raj_57800
Nimbostratus
Thanks a lot....the last rule has solved my problem. - hoolio
Cirrostratus
You could consider changing the HTTP_REQUEST check to either send a redirect to https for all ports or add an else statement. As it is, if you added a default pool to the VIP and the request wasn't on 80 or 443 clients could access any other port on the default pool.when CLIENT_ACCEPTED { if {[TCP::local_port] == 443} { HTTP::disable pool test_pool } } when HTTP_REQUEST { if {[TCP::local_port] == 80} { HTTP::redirect https://xxx.com } else { Reject the request reject } }
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