Forum Discussion
Cody_Conklin_17
Nimbostratus
Jul 29, 2005Simple HTTPS redirect
I have an HTTPS Virtual Server that is terminating SSL. I would also like to take the inbound https requests and append a specific webpage to it. For example, if the user sends a request to https://example.mycompany.com I would like a redirect to https://example.mycompany.com/login_page
I have turned on the http profile on the virtual server and attempted the following iRule, to no avail:
when HTTP_REQUEST {
if { [HTTP::uri] equals "https://example.mycompany.com/" } {
HTTP::redirect https://example.mycompany.com/login_page }
}
Any assistance would be greatly appreciated.
- JRahm
Admin
Try this (untested!):when HTTP_REQUEST { if { [HTTP::host] equals "example.mycompany.com" } { HTTP::redirect https://example.mycompany.com/login_page } }
- Cody_Conklin_17
Nimbostratus
Thanks for your help. - Yeah, that will cause an infinite loop as each request will have the host example.mycompany.com and it will match the if every time. You'll want to put an additional check in there that you'll guaranteed won't get called consecutively.
when HTTP_REQUEST { if { [HTTP::host] equals "example.mycompany.com" } { if { [HTTP::uri] equals "" or [HTTP::uri] equals "/" } { HTTP::redirect https://example.mycompany.com/login_page } } }
when HTTP_REQUEST { if { [HTTP::host] equals "example.mycompany.com" } { if { [HTTP::uri] equals "" or [HTTP::uri] equals "/" } { HTTP::uri "/login_page" } } }
- Cody_Conklin_17
Nimbostratus
As expected, that works perfectly. Thanks so much for your help! - One way to optimize this rule would be to remove the check for the host. If all traffic on the virtual is going through example.mycompany.com, then the first if is overkill. You might say it's just one string compare, but for 1000's of connections it can add up.
when HTTP_REQUEST { if { [HTTP::uri] equals "" or [HTTP::uri] equals "/" } { HTTP::redirect https://example.mycompany.com/login_page } }
when HTTP_REQUEST { if { [ string length [HTTP::uri] ] <= 1 } { HTTP::redirect https://example.mycompany.com/login_page } }
when HTTP_REQUEST { if { [ string index [HTTP::uri] 2 ] equals "" } { HTTP::redirect https://example.mycompany.com/login_page } }
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