Forum Discussion
redirect to https multiple uri's while letting others pass through
I have created a Virtual Server with port 80, created a pool and have added the iRule to the Virtual server. I have a wild card SSL cert that works for our appsf5.com
I have created the following iRule, but it only works once or twice before getting a page not found.
when HTTP_REQUEST
{ if { [HTTP::host] equals "appsf5.com" }{
if { [HTTP::uri] starts_with "/applications/app1" }
{ HTTP::redirect "https://[HTTP::host]/applications/app1/logon.aspx" }
elseif { [HTTP::uri] starts_with "/applications/app2" }
{ HTTP::redirect "https://[HTTP::host]/applications/app2/login.asp" }
elseif { [HTTP::uri] starts_with "/applications/app3" }
{ HTTP::redirect "https://[HTTP::host]/applications/app3/login.asp" }
elseif { [HTTP::uri] starts_with "/applications/app4" }
{ HTTP::redirect "https://[HTTP::host][HTTP::uri]" }
else {HTTP::respond "http://[HTTP::host][HTTP::uri]" }
}
}
56 Replies
- The_Bhattman
Nimbostratus
Hi Deni,
The only command that looks unusually to me is the HTTP::respond line. I have never seen it used like that.
Did you mean HTTP::redirect?
Thanks,
Bhattman - deni_22991
Nimbostratus
I'm sorry, we actually used HTTP:Request. And we were able to make it consistently working by adding a host header to account for the IP being used for the VS for port 80 and 443. - deni_22991
Nimbostratus
Well, we thought we had it working. This is what the iRule actually says
when HTTP_REQUEST
{ if { [HTTP::host] equals "appsf5.com" }{
if { [HTTP::uri] starts_with "/applications/app1" }
{ HTTP::redirect "https://[HTTP::host]/applications/app1/logon.aspx" }
elseif { [HTTP::uri] starts_with "/applications/app2" }
{ HTTP::redirect "https://[HTTP::host]/applications/app2/login.asp" }
elseif { [HTTP::uri] starts_with "/applications/app3" }
{ HTTP::redirect "https://[HTTP::host]/applications/app3/login.asp" }
elseif { [HTTP::uri] starts_with "/applications/app4" }
{ HTTP::redirect "https://[HTTP::host][HTTP::uri]" }
else {HTTP::request}
}
}
It will either work if we use the applications that require SSL, but will not work if it should be a non-SSL application. We have tried making it a http:profile protocol, but with the specific pages we need to redirect to, this will not work.
We have also tried using HTTP::redirect "http://[HTTP::host][HTTP::uri]", which also had mixed results. It would work sometimes and other times we receive a message, The page cannot be displayed
You have attempted to execute a CGI, ISAPI, or other executable program from a directory that does not allow programs to be executed. - Colin_Walker_12Historic F5 AccountSo you're looking to redirect based on the URI ? Something like this perhaps?
when HTTP_REQUEST { if { [HTTP::host] equals "appsf5.com" } { switch [string tolower [HTTP::uri]] { "/applications/app1*" { HTTP::redirect "https://[HTTP::host]/applications/app1/logon.aspx" } "/applications/app2*" { HTTP::redirect "https://[HTTP::host]/applications/app2/login.asp" } "/applications/app3*" { HTTP::redirect "https://[HTTP::host]/applications/app3/login.asp" } "/applications/app4*" { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } } } }
I'm not sure I follow what you were trying to do with the else {HTTP::request} bit. What was that put in to accomplish?
Colin - deni_22991
Nimbostratus
If we only put in the redirects to https: the applications that are not https display a page cannot be displayed error. So yes, we are trying to do a redirect based on URI for those applications that need to be https and let those that are http: just be ignored by the iRule.
- Chris_Miller
Altostratus
Posted By deni on 01/05/2011 11:15 AMIf we only put in the redirects to https: the applications that are not https display a page cannot be displayed error. So yes, we are trying to do a redirect based on URI for those applications that need to be https and let those that are http: just be ignored by the iRule.
Colin's rule (above) will only redirect the users to HTTPS if their requested host name is "appsf5.com" and their URI starts with /app1, /app2, /app3, or /app4. That's all you're looking for, right? - deni_22991
Nimbostratus
That is what I am looking for. I have applied this rule. At the moment it is working. But I will test again in an hour or so. We have had the rule work one time and the next time we tested, only half worked and another time none worked.
I will post again after further testing. - deni_22991
Nimbostratus
The rule does not work as expected. If I use https://appsf5.com/applications/app1/logon.asp it does work. If I try http://appsf5.com/applications/app1/logon.asp, it does not redirect me to the https address. - Chris_Miller
Altostratus
Posted By deni on 01/06/2011 08:21 AM
The rule does not work as expected. If I use https://appsf5.com/applications/app1/logon.asp it does work. If I try http://appsf5.com/applications/app1/logon.asp, it does not redirect me to the https address.
Did you apply it to the Virtual Server listening on port 80 or just the one listening on 443? It should be applied to the one on port 80. That's the only thing I could see being a problem. - deni_22991
Nimbostratus
It is applied only on the Virtual Server listening on port 80.
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
