Forum Discussion
KimiLi_147173
Nimbostratus
Nov 27, 2017Want to rewrite part of host
Hi guys, I'm still new to iRules, I wonder that if it is possible that an iRule can rewrite part of the host instead of all of it.
I mean like, if a client request a host like "123.aaa.com/888/"...
- Nov 28, 2017
If string position is known then you can use
function to grep value like below.getfieldset hostname [getfield [HTTP::host] "." 1] If the URL is xxx.aaa.bbb.com, then getfield command will grep value of 1st position xxx set hostname1 [getfield [HTTP::host] "." 2] If the URL is xxx.aaa.bbb.com, then getfield command will grep value of 2nd position aaaRefer below link. Hope it will be helpful.
Samir_Jha_52506
Noctilucent
Nov 28, 2017If string position is known then you can use
getfieldfunction to grep value like below.
set hostname [getfield [HTTP::host] "." 1] If the URL is xxx.aaa.bbb.com, then getfield command will grep value of 1st position xxx
set hostname1 [getfield [HTTP::host] "." 2] If the URL is xxx.aaa.bbb.com, then getfield command will grep value of 2nd position aaa
Refer below link. Hope it will be helpful.
KimiLi_147173
Nimbostratus
Nov 28, 2017Hi f5_rock,
YOU'RE THE MAN!
I believe this is what I want, according to your suggestion I've got an irule like this:
when HTTP_REQUEST {
Check if host contains "aaa.com"
if {[HTTP::host] contains "aaa.com"}{
Get the xxx from host xxx.aaa.com
HTTP::redirect "https://[getfield [HTTP::host] "." 1].bbb.com[HTTP::uri]"
}
}
And it works! I'll keep on doing further tests to figure out if there's still room to make it better.
Thanks again!
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