Forum Discussion
splavery_111804
Nimbostratus
May 22, 2008Remove port redirect from URL
Hi, newbie here with what should be an easy iRule.
We use port redirects on our http and https sites, but in some cases, the redirected port gets inserted into the URL and passed back t...
hoolio
Cirrostratus
May 22, 2008Hi there,
If you know that the server will only use its own port in the Location header in redirects, you could remove : where is the server's port (any number of digits) using string map. Or if you want to replace the colon followed by one or more digits, you could use regsub. The first approach would be more efficient as it doesn't use regexes. The second would be more effective if you don't know what port will be included.
when HTTP_RESPONSE {
Check if a response is a redirect
if {[HTTP::is_redirect]}{
log local0. "Original Location: [HTTP::header value Location]"
Assume the server will use it's own TCP port in redirects and remove it.
HTTP::header replace Location [string map [list ":[LB::server port]" ""] [HTTP::header value Location]]
log local0. "Updated location (string map): [string map [list :[LB::server port] ""] [HTTP::header value Location]]"
Use regsub to remove the colon and any characters up to the next forward slash.
HTTP::header replace Location [regsub {:[0-9]+?(?=/)} [HTTP::header value Location] ""]
log local0. "Updated Location (regsub): [regsub {:[0-9]+?(?=/)} [HTTP::header value Location] ""]"
}
}
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
