Forum Discussion
kg_50758
Nimbostratus
Jul 25, 2007Standard HTTPs redirect
I am new to iRules, when i tried the standard https redirect if the url ends with '.do, could not get it to working. iRules i used is as below
when HTTP_REQUEST {
if { [HTTP::uri] ends_with "*.do" } {
HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
}
}
Also tried below iRules, just to redirect all the trafic to https, even this is not working for me.
when HTTP_REQUEST {
set uri [HTTP::uri]
HTTP::redirect "https://[HTTP::host]$uri"
}
I want https redirect to happen on the client to f5 and not on the f5 to server.
client--->f5--->server
Searched for the solution in the forum, could not find one. Can some one HELP.
Thanks in Advance
KG
15 Replies
- Deb_Allen_18Historic F5 AccountLooks like you have some missing CR/LF in your rule, as the error message is reporting lines 5 - 9 as a single line of code.01070151:3: Rule [log_request_response] error:
line 5: [wrong args] [set headers "Headers: " foreach aHeader [HTTP::header names] { set headers "$headers$aHeader: [HTTP::header value $aHeader] " } log local0. "Request Info: $request_info; Response Info: status: [HTTP::status] $headers"]You'll need to make sure there's a new line for each line of code in the iRule hoolio provided.
HTH
/deb - kg_50758
Nimbostratus
Thanks for all your help.
I got http to https redirect working for all request coming in.
Now i want to get the https redirect only for the url containing '.do' in the url. Is there any iRule function to check url which contains '.do'?
Thanks again
KG. - You can use the HTTP::uri command along with the "contains" operator to check for a .do in the URI. Something like this...
when HTTP_REQUEST { if { [HTTP::uri] contains ".do" } { do something... } }
-Joe - hoolio
Cirrostratus
Out of curiosity, what was the issue? Also, it might not matter much, but I think it would be more exact to check to see if HTTP::path ends in .do. HTTP::uri contains the complete HTTP object and the query string. HTTP::path contains only the object (and not the query string). So '[HTTP::uri] ends_with .do' would return true for a request like /some/file.php?param=test.do
Aaron - kg_50758
Nimbostratus
SSLClient was not assigned for https virtual server after we assigned the client, https redirect for all request started working. Used Path instead of uri and with contains and ends with, code is as below. Thanks your help.
when HTTP_REQUEST {
log local0. "client [IP::client_addr] -> [HTTP::host] for uri: [HTTP::uri], path: [HTTP::path]"
if { ([HTTP::path] contains ".do") or ([HTTP::path] ends_with ".jsp") } {
HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
}
}
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
