Forum Discussion
iRules - Remove WWW AND replace "Host"
Hello,
I am sorry if this is very easy to do, but I am really new to F5 and iRules.
We have an iRule in place which replaces the domain part of a URL. This rule is below.
The situation is this: If a user visits location1.domain1.com , it translates to location1.primarydomain.com, and then our webserver handles redirection to .
That part is working great. HOWEVER, if a user appends www in front of the URL, i.e. , the URL is then , and our webserver doesn't know what do to.
I would like the iRule to remove www, and then translate it to location1.primarydomain.com (if you know what I mean).
Is this possible?
when HTTP_REQUEST { if { [HTTP::host] ends_with ".domain1.com" } { HTTP::header replace "Host" [string map {".domain1.com" ".primarydomain.com"} [HTTP::host]] } }
2 Replies
- Vijay_E
Cirrus
You need this logic inserted into your existing iRule:
if { [HTTP::host] starts_with "www." } { HTTP::host [getfield [HTTP::host] "www." 2] }or you can try this if the above doesn't give the right result:
if { [HTTP::host] starts_with "www." } { HTTP::host [string range [HTTP::host] 4 end] } Hi networkdawg,
you may try the iRule below.
It uses the
command to extract the first three dotted domain elements (e.g. four.third.second.frist) from the requested HOST-header, then passes the information to a[domain]
command to extract the third element and adds the new second and first dotted domain elements via TCL concentation...[getfield]when HTTP_REQUEST { if { [string tolower [HTTP::host]] ends_with ".domain1.com" } then { HTTP::host "[getfield [domain [HTTP::host] 3] "." 1].primarydomain.com" } }Cheers, Kai
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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