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://[H...
Apr 25, 2006
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.
http://tmml.sourceforge.net/doc/tcl/index.html Click here
http://tmml.sourceforge.net/doc/tcl/string.html Click here
Citizen had one thing wrong with the trimright subcommand. It will trim the supplied characters from the end of the string, not all characters after the supplied string. If you know the port will be 8010, you could hardcode it like this
when HTTP_REQUEST {
if { [HTTP::host] ends_with ":8010" } {
set http_host [string trimright [HTTP::host] ":8010"]
HTTP::redirect "https://$http_host[HTTP::uri]"
}
}
Or you could just omit the first ends_with check as the trimright will return the entire string if the supplied matching string isn't found
when HTTP_REQUEST {
HTTP::redirect "https://[string trimright [HTTP::host] ":8010"][HTTP::uri]"
}
But, if you don't know what the port will be, you could write it more genericly like this:
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]"
}
It's less overhead to hard code it, but you have options either way.
-Joe
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