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]]
}
}
Try:
when HTTP_RESPONSE {
if { [HTTP::is_redirect] } {
HTTP::header replace Location [getfield [HTTP::header value Location] : 1]
}
}
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?
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
}
}
You could use string commands for this as well. Here are a few options which should be a bit more efficient than regsub:
Aaron