Forum Discussion
dirken
Nimbostratus
May 02, 2012remove tcp port from Location header in redirect
Hi folks, newbie and tasked to remove the tcp port from a redirect's Location header. Without a test system I cannot check it and would appreciate any feedback before going live. Would this iRule work?
when HTTP_RESPONSE {
if { [HTTP::is_redirect] } {
[string map [list :52600 ""] [HTTP::header Location]]
}
}
4 Replies
- MiLK_MaN
Nimbostratus
Try:
when HTTP_RESPONSE {
if { [HTTP::is_redirect] } {
HTTP::header replace Location [getfield [HTTP::header value Location] : 1]
}
} - dirken
Nimbostratus
Two problems:
1. if the Location contains an absolute path like "https://somehost:52600", then this iRule would redirect me to "https" with nothing behind it, correct?
2. if the Location contains an URI behind the host like "somehost:52600/somepath/somefile", then the iRule would redirect me to "somehost" without any path, correct? - MiLK_MaN
Nimbostratus
You are right. Apologies for not considering that.
when HTTP_RESPONSE {
if { [HTTP::is_redirect] } {
regsub -all ":52600" [HTTP::header Location] "" newlocation
HTTP::header replace Location $newlocation
}
}
- hoolio
Cirrostratus
You could use string commands for this as well. Here are a few options which should be a bit more efficient than regsub:
https://devcentral.f5.com/wiki/iRules.RewriteHTTPRedirectPort.ashx
Aaron
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
