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 to the client and obviously breaks the session.
Example: https://secure.mysite.com:8467/comparison.aspx
I've tried to write a couple of irules to remove the 8467, without success.
Any help is greatly appreciated.
5 Replies
- hoolio
Cirrostratus
Hi 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 - hoolio
Cirrostratus
It looks like the forum is breaking the display of some meta-characters after the upgrade. The regex should be { : [ 0 - 9 ] + ? ( ? = / ) } without any spaces.
Aaron - splavery_111804
Nimbostratus
Thanks for the reply, but I can't quite get this to work without error. I'm probably not replacing some of your commands with the right variables for this site.
It's only one site that would be affected, and it is only using the server port, so option 1 is what I'm working with.
I need to change https://secure.mysite.com:8467/comparison.aspx to https://secure.mysite.com/comparison.aspx
It's possible that other URI's may be affected, but as far as the URL/port go, those are the only ones I'm worried about.
Thanks again. - splavery_111804
Nimbostratus
(post deleted)
After a second look, it appears that may be a code issue, not part of the irule - hoolio
Cirrostratus
You should be able to check what the original location header value was in the /var/log/ltm log file. The above rule wouldn't have modified the protocol. If you want to change it from http:// to https://, you can modify the rule: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. Also replace http:// with https://. HTTP::header replace Location [string map -nocase [list http:// https:// ":[LB::server port]" ""] [HTTP::header value Location]] log local0. "Updated location (string map): [string map -nocase [list http:// https:// ":[LB::server port]" ""] [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
