Forum Discussion
slackwaresuppor
Nimbostratus
May 28, 2008stripping data
how would i strip the www. off of www.domain.com??
10 Replies
- JRahm
Admin
Like this:[getfield [HTTP::host] ".domain.com" 2]
- slackwaresuppor
Nimbostratus
when HTTP_REQUEST { - slackwaresuppor
Nimbostratus
also would like to try and put in an if statement, if it has www, strip it off, if not, just forward with the domainname. - slackwaresuppor
Nimbostratus
so this is what ive come up with.. - slackwaresuppor
Nimbostratus
also.. the domain.com could be anything not just a single domain, so i need to check all incoming www.? - slackwaresuppor
Nimbostratus
ahhhhh... - In this example you are doing the getfield twice which is causing double string allocations. If all you want to do is check whether a "www." is prefixing your domain, you can do so with the "starts_with" operator. And then, since you know you want to strip off the first 4 characters, you can use the "string range" command to do that.
when HTTP_REQUEST { set host [HTTP::host] if { [HTTP::host] starts_with "www." } { set host [string range [HTTP::host] 4 end] } HTTP::redirect "https://www.domain1.com/nsa/+homePage=$host" }
- John_Alam_45640Historic F5 AccountSince it is fun we are after, how is this:
- Deb_Allen_18Historic F5 AccountOuch, please let's not go with regsub to solve such a simple problem. Very pretty all on one line & everything, but very expensive command to invoke regardless how simple the operation itself might be.
which will return only the last 2 parts of any domain name.when HTTP_REQUEST { HTTP::redirect "https://www.domain1.com/nsa/+homePage=[domain [HTTP::host] 2]" }
when HTTP_REQUEST { if { [HTTP::host] starts_with "www." } { HTTP::redirect "https://www.domain1.com/nsa/+homePage=[domain [HTTP::host] 2]" } else { HTTP::redirect "https://www.domain1.com/nsa/+homePage=[HTTP::host]" } }
- Deb_Allen_18Historic F5 Accountoh, that was ugly.
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