Forum Discussion
Randy_Moran_110
Nimbostratus
Feb 27, 2008http-to-https redirect problem
Hi all,
I'm trying to get the following to work. If the client is asking for "http://portal.innovation.net", he's directed to "https://portal.innovation.net/PortalWAR/appmanager/portal/home"
If he's asking for "http://portal.innovation.net/blah/blah", he's directed to https://portal.innovation.net/blah/blah"
In other words, if he's asking for an explicit path, he's redirected to his path via https. If he's not asking for a path, he's directed to https://portal.innovation.net/PortalWAR/appmanager/portal/home.
when HTTP_REQUEST {
if {[HTTP::uri "http://portal.innovation.net"]}{
HTTP::redirect "https://[HTTP::host]:443/PortalWAR/appmanager/portal/home"
} else {
HTTP::redirect "https://[HTTP::host]:443/[HTTP::uri]"
}
}
Is there some error in this rule that would cause it not to work? When I apply it, I get a host unaccessible error.
- The_Bhattman
Nimbostratus
Try thiswhen HTTP_REQUEST { if {[HTTP::host equals "portal.innovation.net"]} { HTTP::redirect "https://[HTTP::host]/PortalWAR/appmanager/portal/home" } else { HTTP::redirect "https://[HTTP::host]/[HTTP::uri]" } }
- Randy_Moran_110
Nimbostratus
Thanks for answering my post, cmbhatt. I really appreciate it. The one thing I see might be a problem with your solution is that in my problem, in both cases, the host is the same. I mean that the first part of the url will be the same in both requests; it's only a matter of if the user is asking for an explicit path after or not. I'll try it and see what happens. - The_Bhattman
Nimbostratus
Here is a better piece that is more specific to what the user enters, rather then using IF-ELSE statement i used the Switch statement.when HTTP_REQUEST { switch [HTTP::URI] { "portal.innovation.net" { switch [HTTP::uri] { "/" { HTTP::redirect "https://[HTTP::host]/PortalWAR/appmanager/portal/home" } "/blah/blah" { HTTP::redirect "https://[HTTP::host]/[HTTP::uri]" } } } } }
- The_Bhattman
Nimbostratus
Here is a better piece that is more specific to what the user enters, rather then using IF-ELSE statement i used the Switch statement.when HTTP_REQUEST { switch [HTTP::URI] { "portal.innovation.net" { switch [HTTP::uri] { "/" { HTTP::redirect "https://[HTTP::host]/PortalWAR/appmanager/portal/home" } "/blah/blah" { HTTP::redirect "https://[HTTP::host]/[HTTP::uri]" } } } } }
- Randy_Moran_110
Nimbostratus
Yeah that seems to do what I need. Thanks a lot for the help. One last question concerning this rule: If i want to say, basically, "if there is anything after the host name, redirect it to the hostname and whatever follows in the uri," how would I do that? - The_Bhattman
Nimbostratus
Yes there are things you can use to match a patternwhen HTTP_REQUEST { switch -glob [HTTP::URI] { "portal.innovation.net" { switch [HTTP::uri] { "/" { HTTP::redirect "https://[HTTP::host]/PortalWAR/appmanager/portal/home" } "/blah/blah*" { HTTP::redirect "https://[HTTP::host]/[HTTP::uri]" } "*blah" { HTTP::redirect "https://[HTTP::host]/[HTTP::uri]" } "blah*" { HTTP::redirect "https://[HTTP::host]/[HTTP::uri]" } "b?ah" { HTTP::redirect "https://[HTTP::host]/[HTTP::uri]" } } } } }
- Nicolas_Menant
Employee
hi, - Randy_Moran_110
Nimbostratus
Thanks a lot for all your help guys. - dennypayne
Employee
Posted By nmenant on 02/28/2008 10:24 AM
- The_Bhattman
Nimbostratus
Here it is correctedwhen HTTP_REQUEST { switch -glob [HTTP::host] { "portal.innovation.net" { switch -glob [HTTP::uri] { "/" { HTTP::redirect "https://HTTP::host]/PortalWAR/appmanager/portal/home" } "/blah/blah*" { HTTP::redirect "https://[HTTP::host]/[HTTP::uri]" } "*blah" { HTTP::redirect "https://[HTTP::host]/[HTTP::uri]" } "blah*" { HTTP::redirect "https://[HTTP::host]/[HTTP::uri]" } "b?ah" { HTTP::redirect "https://[HTTP::host]/[HTTP::uri]" } } } } }
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