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.
7 Replies
- 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.
If you wanted to list out all of the ports you could use a datagroup for simplified management.
Else, here's an example using regsub.
TCL man page for regsub: Click herewhen 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 } }
Aaron - 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,
I was thinking along the same lines, until I considered that the Location value must be an absolute URL, including the protocol. So the Location header contains "http(s)://whatever..."
ftp://ftp.rfc-editor.org/in-notes/rfc2616.txt
14.30 Location
The Location response-header field is used to redirect the recipient
to a location other than the Request-URI for completion of the
request or identification of a new resource. For 201 (Created)
responses, the Location is that of the new resource which was created
by the request. For 3xx responses, the location SHOULD indicate the
server's preferred URI for automatic redirection to the resource. The
field value consists of a single absolute URI.
Location = "Location" ":" absoluteURI
An example is:
Location: http://www.w3.org/pub/WWW/People.html
Aaron - Andrew_Abplanal
Nimbostratus
Thanks for the information.....
Here is how I used it.....
The condition here is the client is using SSL to the F5, the F5 based on the URI will send the connection to either HTTP or HTTPS pools.
The Backend server pools are IIS 6 and they return the port they are using when they do a courtesy redirect.
When the backend pool is HTTP it also send the Location back as HTTP so this has to be changed back to HTTPS.
if {[HTTP::is_redirect]}{
log local2. "redirect from SSL"
log local2. "Location = [HTTP::header value 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+/} [HTTP::header value Location] "/" location
if the backend server is HTTP the header variable "location" is modified to use HTTPS
HTTP::header replace Location [string map { "http:" "https:" } $location]
log local2. "Fixed Location = [HTTP::header value Location]"
}
} - 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?
Here's a link to the 9.2.x config guide:
Click here
The heading is: Rewriting an HTTP redirection
I'm not certain this would remove the port, but I think it should.
Aaron - JRahm
Admin
ah, good catch. So would indexing the first two values be more or less expensive in cycles than regsub?
set myLocation [split [HTTP::header value Location] ":"]
HTTP::header replace Location [lindex $myLocation 0]:[lindex $myLocation 1]/ - Colin_Walker_12Historic F5 AccountI'm pretty sure 5 lindexes would be more efficient than regex. :p
Colin
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