Forum Discussion
Robert_47833
Aug 12, 2011Altostratus
how to change a string ,such as add a number after some letters
Hi,dear irule
I want to change the host name to another one
for example
www.cjj.com---->www2.cjj.com
cjj.com------>cjj2.com
*.cjj.com---->*2.cjj.com
domain [HTTP::host] 2 will return cjj.com if it is "www.cjj.com"
Thanks in advance
- Ed_Hammond_2611NimbostratusTry something like:
regsub {^([^\.]*).} [HTTP::host] {${1}2.} newhost log local0. "[HTTP:host] $newhost"
- Colin_Walker_12Historic F5 AccountWhile regsub would technically work, it's going to induce a lot of overhead. There are lots of other ways to go about that: scan, string map, etc.
- hooleylistCirrostratusI think something like this should work:
switch [string tolower [HTTP::host]] { "cjj.com" { HTTP::header replace Host "cjj2.com" } default { HTTP::header replace Host "[getfield [HTTP::host] "cjj2.com" 1]2.cjj.com" } }
- Robert_47833AltostratusHi,all friends,I use irule below to achieve this:
- Colin_Walker_12Historic F5 AccountI'm glad to see that you got it working. Bonus points for using the scan command, very cool and efficient. ;)
- Robert_47833Altostratushaha,thanks,I have learned a lot from here
- Robert_47833AltostratusHi,by the way,do u know why I can't add number "2" in HTTP::redirect "http://$domainfirst2$domainleft[HTTP::uri],how to achieve this?
- Colin_Walker_12Historic F5 AccountIt's not working because it doesn't know where the first variable stops, and is trying to incorporate the 2 as part of the variable name.
% set h1 www.srwd www.srwd % set h2 9.com 9.com % puts $h1$h2 www.srwd9.com % puts $h12$h2 can't read "h12": no such variable % puts ${h1}2${h2} www.srwd29.com %
- Robert_47833Altostratusoh,Colin
Recent Discussions
Related Content
- May 24, 2019Former Member
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