Forum Discussion
Joe_Pipitone
Feb 14, 2011Nimbostratus
using HTTP::host with 2 hostnames
This iRule triggers an error in the F5 log: "TCL error: irule-test HTTP_REQUEST - cant use non-numeric string as operand of - while executing if {[string tolower [HTTP::host]] eq www.oneofourdomains.com}{ HTTP::redirect http://oneofourdomains.com[HTTP::uri] } elseif... default arm line 2 invoked from within switch -glob [string tolower [HTTP::uri]] { /events/a-company-event-2010* { HTTP::redirect http://oneofourdomains.com/..." The original irule looks like so: oneofourdomains.com rewrite rules
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"/events/a-company-event-2010*" {
HTTP::redirect "http://oneofourdomains.com/Events/event-2011"
}
default {
if {[string tolower [HTTP::host]] eq "www. oneofourdomains.com"}{
HTTP::redirect "http://oneofourdomains.com[HTTP::uri]"
} elseif {[string tolower [HTTP::host]] eq "www. adifferentone.com" - "adifferentone.com" } {
HTTP::redirect "http://oneofourdomains.com[HTTP::uri]"
}
}
}
}
I've been able to get this iRule to work by using this syntax: oneofourdomains.com rewrite rules
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"/events/a-company-event-2010*" {
HTTP::redirect "http://oneofourdomains.com/Events/event-2011
}
default {
if {[string tolower [HTTP::host]] eq "www.oneofourdomains.com"}{
HTTP::redirect "http://oneofourdomains.com[HTTP::uri]"
} elseif {[string tolower [HTTP::host]] eq "www.adifferentone.com" } {
HTTP::redirect "http://adifferentone.com[HTTP::uri]"
} elseif {[string tolower [HTTP::host]] eq "adifferentone.com" } {
HTTP::redirect "http://adifferentone.com[HTTP::uri]"
}
}
}
}
However, I'd like to cut back on the number of elseif statements and force this rule to see the www.adifferentone.com as well as adifferentone.com (without www) I'm using a similar syntax in a different iRule, however I am not sure what I'm doing wrong in this instance. I'm attempting to use: } elseif {[string tolower [HTTP::host]] eq "www. adifferentone.com" - "adifferentone.com" } { and the bigip doesn't like it. I'm thinking this isn't correct because it needs to be inside another switch statement? Also, I'm wrapping my code snippets with code brackets and the forums don't seem to like that either? It seems to be replacing [ code ] with < pre class= "code" >3 Replies
Sort By
- switch accepts the hyphen syntax to use the same action for multiple string patterns. 'if' does not. You could use another switch nested in the first switch to do this:
when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/events/a-company-event-2010*" { HTTP::redirect "http://oneofourdomains.com/Events/event-2011" } default { switch [string tolower [HTTP::host]] { "www. oneofourdomains.com" - "www. adifferentone.com" - "adifferentone.com" { HTTP::redirect "http://oneofourdomains.com[HTTP::uri]" } } } } }
- Ignore the last message, it was my mistake, it works great.
- Glad that works for you.
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