Forum Discussion
CraigM_17826
Altocumulus
May 13, 2010Removing port from a redirect
Hi all,
One of our web developers has asked me if we could strip off a port number in a redirect they are doing. I thought the following would do this, but it doesn't appear to work.
when HTTP_REPSONSE {
if { [HTTP::is_redirect] } {
if { [HTTP::header Location] contains "www.acme.com:10040" } {
log "Original Location value: [HTTP::header Location]"
HTTP::header replace Location [string map -nocase {www.acme.com:10400 www.acme.com} [HTTP::header value Location]]
log "Updated Location value: [HTTP::header Location]"
return
}
}
}
And here is what is written to the log
Original Location value: www.acme.com:10040/secure/discussion-forum
Updated Location value: www.acme.com:10040/secure/discussion-forum
Note: actually the log includes http but if I enter in a URL in this new forum s/w it does odd things to it.
Any help appreciated. Craig
9 Replies
- hoolio
Cirrostratus
Hi Craig,
That should work fine to remove the port from redirects. However, the value for HTTP::header Location is cached in the same iRule event. and priority. You can get around this while testing by adding a second HTTP_REQUEST event:when HTTP_RESPONSE { if { [HTTP::is_redirect] } { if { [HTTP::header Location] contains "www.acme.com:10040" } { log local0. "Original Location value: [HTTP::header Location]" HTTP::header replace Location [string map -nocase {www.acme.com:10400 www.acme.com} [HTTP::header value Location]] } } } when HTTP_RESPONSE priority 501 { if { [HTTP::is_redirect] } { Debug logging only. Remove this event once done testing log local0. "Updated Location value: [HTTP::header Location]" } }
Aaron - CraigM_17826
Altocumulus
Hi Aaron,
hmm, tried what you suggested and the log entry in the other HTTP_RESPONSE section doesn't display a value for the header, it is just blank.
I have used this code logic before and it worked, but the only difference was that the hostname was being changed with no explicit port numbers. I'll do some more testing but is there any other way I could do this?
Regards
Craig - hoolio
Cirrostratus
Hi Craig,
I had the logging in HTTP_REQUEST instead of HTTP_RESPONSE. Can you try the updated version above?
Thanks, Aaron - CraigM_17826
Altocumulus
Hi Aaaron,
ahh that worked in so far as it displays something now, but it is showing the Location unchanged, so either
1. it's still cached
2. The HTTP::header replace is not working.
Here is the entry from the ltm log
Updated Location value: http://www.acme.com:10040/secure/discussion-forum
As I mentioned earlier I have pretty much the same block of code that does work, but there is one other major difference between these two situations. In the case where it works the redirect is generated on host-a to host-b whereas in the one that isn't working it is redirecting to itself. Not sure if this should make a differene, but this along with the use of a port number are the only differences I can fathom at the moment.
On a positive side, it looks as if F5 engineering think they have finally tracked down the cause of our memory leak and can reproduce it in their labs. Yay!!!
Craig - CraigM_17826
Altocumulus
Hi Aaron,
just noticed this on the Wiki for HTTP::header
** There is an issue where HTTP::header values can remove colons in the header values it returns. The actual header values are unchanged. This issue is tracked as CR98328. **
I'm wondering if this is the issue. I'll do some more testing.
Craig - hoolio
Cirrostratus
Nice find. CR98328 was an issue in 9.4.x and fixed in 10.0.0 per SOL8676. Which LTM version are you testing this on?
SOL8676: The HTTP::header values iRule command removes colon characters from header values
https://support.f5.com/kb/en-us/solutions/public/8000/600/sol8676.html
If that is the problem, you could try removing the colons in the iRule as well. It wouldn't be pretty but it should work.
[HTTP::header Location] contains "www.acme.com:10040" -> [HTTP::header Location] contains "www.acme.com10040"
...
string map -nocase {www.acme.com:10400 www.acme.com} -> string map -nocase {www.acme.com10400 www.acme.com}
Aaron - CraigM_17826
Altocumulus
Hi Aaron,
we are running 10.xxx and oddly enough it has started to work. Arrgh. All I did was to re-enter in the lines of code in the iRile and it started to work. Just wondering if somehow I managed to enter in a a non printable character somewhere. Odd, but it seems to be working consistantly now which is a releif. Now our developers have thrown up another request (sigh). I 'll start a new topic on this if I can't nut it out by myself.
Once again thank for all of your help, past present and future!
Craig - hoolio
Cirrostratus
That's an odd one. Glad to hear it's working now though. Let us know if you have any more questions.
Aaron - reidg
Nimbostratus
I have read through about dozen threads to convert https://www.server.com:8080 to https://www.sever.com.
This is one that works! Thanks for documenting this.
When a vendor hard codes Nginx to use port 8080 for https, it gets a little messy. ;)
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