Forum Discussion
Stephen_Archer_
Jul 03, 2006Historic F5 Account
re-write HTTP Response code 302 to HTTPS
Hi, I hope someone can help.
I have adapted the following code from a previous post:
when HTTP_RESPONSE {
if { [HTTP::status] contains "302"} {
if { [HTTP::header location] contains "http://www.test.com/portal/" } {
set newLoc [string map {http://www.test.com/portal/ https://www.test.com/portal/} [HTTP::header location] ]
HTTP::header replace location "$newLoc"
}
}
}
When a server sends a 302 response, the response includes a location field. A packet capture shows that the loaction field is set to "http://www.test.com/portal/", however I see no log entry and the header is not modified.
All I need to do is to change http to https, and leave the rest of the string intact. Am I going about this the right way?
Hope you can help!
Thank you,
A'
2 Replies
- Colin_Walker_12Historic F5 AccountWell, the first thing I would do is add a log statement to each step of the rule, to make sure that all the different sections are being evaluated as expected.
Something like:when HTTP_RESPONSE { if { [HTTP::status] contains "302"} { log local0. "Status code captured : [HTTP::status]" if { [HTTP::header location] contains "http://www.test.com/portal/" } { log local0. "Location header matches : [HTTP::header location" set newLoc [string map {http https} [HTTP::header location] ] log local0. "New string location: $newLoc" HTTP::header replace location "$newLoc" } } }
This should show you what's happening in the rule and what's not. Also note that I modified the string map command to be much simpler. Since the URLs are the same, you only need to change the http / https portion.
Give this a shot and see if you can figure out what's happening / not happening. Let us know if you've got more questions.
HTH,
Colin - Stephen_Archer_Historic F5 AccountColin,
Brilliant! It worked perfectly. I wasn't too far away... your example has proved that logging is useful in troubleshooting - now I can see the entire URL that matches and helped me fix another issue we have been experiencing.
Thank you very much indeed.
Arch.
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
