Forum Discussion
10 Replies
Sort By
- JRahmAdminLike this:
[getfield [HTTP::host] ".domain.com" 2]
- slackwaresupporNimbostratuswhen HTTP_REQUEST {
- slackwaresupporNimbostratusalso would like to try and put in an if statement, if it has www, strip it off, if not, just forward with the domainname.
- slackwaresupporNimbostratusso this is what ive come up with..
- slackwaresupporNimbostratusalso.. the domain.com could be anything not just a single domain, so i need to check all incoming www.?
- slackwaresupporNimbostratusahhhhh...
- 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.