Forum Discussion
Andrew_Abplanal
Nimbostratus
Feb 28, 2007strip port information from URL on courtesy redirect
I have found that some versions of IIS add the server’s port information the URL on a courtesy redirect.
Currently I am stripping the port information using this iRule…..
if { [HTTP::header value Location] contains ":29359/" } {
HTTP::header replace Location [string map { ":29359/" "/" } [HTTP::header value Location]]
} elseif { [HTTP::header value Location] contains ":29004/"} {
HTTP::header replace Location [string map { ":29004/" "/" } [HTTP::header value Location]]
} elseif { [HTTP::header value Location] contains ":25621/" } {
HTTP::header replace Location [string map { ":25621/" "/" } [HTTP::header value Location]]
}
I would like to find a way to make this generic and simply strip out any port information.
- hoolio
Cirrostratus
The only way I can think of handling this is to use a regular expression. I'm not sure whether it's better to use the regex or list out all possible values for the port.when HTTP_RESPONSE { set location [HTTP::header value Location] check to see if the Location header is set if { not ($location == "") { look to see if there is a string that contains a ":" followed by any number of digits followed by a forward slash if so, replace that string with a forward slash regsub {:\d+/} $location "/" newLocation replace the existing Location header with the new value HTTP::header replace Location $location } }
- JRahm
Admin
Would something like this work for you?when HTTP_REQUEST { if { [HTTP::header value Location] contains ":" } { HTTP::header replace Location [lindex [split [HTTP::header value Location] ":"] 0]/ } }
- hoolio
Cirrostratus
Hey citizen_elah, - Andrew_Abplanal
Nimbostratus
Thanks for the information..... - hoolio
Cirrostratus
If you need to rewrite the redirects from HTTP to HTTPS, have you tried using rewrite redirects on the virtual server's HTTP profile? - JRahm
Admin
ah, good catch. So would indexing the first two values be more or less expensive in cycles than regsub? - Colin_Walker_12Historic F5 AccountI'm pretty sure 5 lindexes would be more efficient than regex. :p
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