Forum Discussion
Jason_Roppolo_3
Apr 21, 2006Historic F5 Account
http redirect and port stripping
All,
Can anyone assist me with an iRule that would strip a certain string out of a url?
The customer has a vip that is 10.0.0.2:8010 which does a redirect to https://[HTTP::host][HTTP::uri] using the following:
when HTTP_REQUEST {
HTTP::redirect "https://[HTTP::host][HTTP::uri]
The only issue with this is that it redirects to https://foo.com:8010/mysupersecreturi/blammo
I can't do a hard coded redirect because they are using http headers on the back end web server so don't even try it!
I think I am missing something pretty simple but after 12 hours of GTM installation my brain is mush!
Thanks for your help...
- Elon_Richards_1NimbostratusYour assumption is correct.
- JRahmAdminTry this:
when HTTP_REQUEST { if { [HTTP::host] ends_with ":8010" } { set http_host [string trimright [HTTP::host] ":"] HTTP::redirect "https://$http_host[HTTP::uri] } }
- Elon_Richards_1NimbostratusThanks for your response.
- The "string trimright" command is a internal TCL command that is supported in our iRules language. Here's the TCL reference site and the link to the usage of the "string" command.
when HTTP_REQUEST { if { [HTTP::host] ends_with ":8010" } { set http_host [string trimright [HTTP::host] ":8010"] HTTP::redirect "https://$http_host[HTTP::uri]" } }
when HTTP_REQUEST { HTTP::redirect "https://[string trimright [HTTP::host] ":8010"][HTTP::uri]" }
when HTTP_REQUEST { set http_host [HTTP::host] look for last occurance of ":" in HTTP::host set colon [string last ":" [HTTP::host]] if { $colon != -1 } { if a colon is found, then extract characters 0 up until 1 before the colon set http_host [string range [HTTP::host] 0 [expr $colon - 1]] } HTTP::redirect "https://$http_host[HTTP::uri]" }
- Deb_Allen_18Historic F5 AccountNot to say your algorithm isn't the prettiest baby I ever saw, Joe, but since there can only be one : in a host header, I just use this:
[getfield [HTTP::hostname] ":" 1]
- Jason_Roppolo_3Historic F5 AccountI think Deb Allen wins this one with the most elegant and simplest.....
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