Forum Discussion
Trying to replace the header host value if it doesn't match 2 conditions
I am trying to write an irule that will replace the header host value if it does not meet 1 given value or a 2nd given value. I tried the below irule based on info I gathered from various posts but it does not like the syntax. I am using version 13.1.1.2
when HTTP_REQUEST {
if { ([HTTP::header host] not "abc.host.com") or \
([HTTP::header host] not "xyz.host.com") } {
HTTP::header replace Host "abc.host.com"
}
}
If I try to save the above rule, I get this error: 01070151:3: Rule [/Common/rule_abc_host_header_replace] error: /Common/rule_abc_host_header_replace:2: error: [parse error: PARSE syntax 51 syntax\ error\ in\ expression\ \"\ (\[HTTP::header\ host\]\ not\ \"abc.host.com\")\ or\ \\\n\ \ \ \ \ \ \ \ \ (...\":\ looking\ for\ close\ parenthesis][{ ([HTTP::header host] not "abc.host.com") or \
([HTTP::header host] not "xyz.host.com") }]
10 Replies
- Vijay_E
Cirrus
Sorry, edited the previous code snippet. "set" should be used for variable creation.
- pchace
Nimbostratus
Oh right, I should have know that as well. However it still does not work as it does not like something in the syntax. Also I am not triggering it based on the host. The item that is supposed to trigger the event is if the http header does not have a specific hostname in the header.
- Vijay_E
Cirrus
Based on the error message, it looks like you have an extra ] in the set command.
- Vijay_E
Cirrus
Try:
set HOST [string tolower [HTTP::host]] if { (not ($HOST eq "abc.host.com")) or (not ($HOST eq "xyz.host.com")) } {- pchace
Nimbostratus
Thanks Vijay,
Let me know if I did something wrong, but I entered the rule like this:
when HTTP_REQUEST {
HOST = [string tolower [HTTP::host]]
if { (not ($HOST eq "abc.host.com")) or
(not ($HOST eq "xyz.host.com")) } {
HTTP::header replace Host "abc.host.com"
}
}
And it gave me this error: 01070151:3: Rule [/Common/rule_header_replace_abc] error: /Common/rule_header_replace_abc:2: error: [undefined procedure: HOST][HOST = [string tolower [HTTP::host]]]
- DanS92
Cirrus
Wouldn't this work as a Local Traffic Policy configured like this?:
- pchace
Nimbostratus
I am so accustomed to using irules for everything and I am not real familiar with Local Traffic Policy. However this looks like it will do what I need. I will test it and let you know. Thanks!
- DanS92
Cirrus
I am too... But I’ve spent a good amount of time over the last year converting everything I can from iRules to Local Traffic Policies. Especially iRules that direct certain traffic to certain pools based on hostname, because it shows up much better on the Network Map.
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
