# Irule not working

**URL:** <https://community.f5.com/t/irule-not-working/19486>\
**Category:** Technical Forums\
**Tags:** irules, devops, application-delivery\
**Created:** [June 25, 2015, 9:25am UTC](https://community.f5.com/t/irule-not-working/19486 "2015-06-25T09:25:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohanish\_169493](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@Mohanish\_169493](https://community.f5.com/u/Mohanish_169493)\
**Post date:** [June 25, 2015, 9:25am UTC](https://community.f5.com/t/irule-not-working/19486/1 "2015-06-25T09:25:19Z")

</div>

Hi,

I have written an Irule as below when HTTP\_REQUEST { if{([HTTP::host] contains"[eulyncweb01.csmglobal.net](http://eulyncweb01.csmglobal.net)")and([HTTP::uri] contains"/RequestHandler/Files/UCPhone")

node 10.96.96.16 80

} else{ HTTP::redirect https://[HTTP::host][HTTP::uri] } }

However upon execution it is throwing below error Please if someone can help with as to what is wrong

n 25 10:57:19 nladmll003 err tmm1[11990]: 01220001:3: TCL error: /Common/Lync-test - invalid command name “if{([eulyncweb01.csmglobal.net](http://eulyncweb01.csmglobal.net)” while exe cuting “if{([HTTP::host] equals"[eulyncweb01.csmglobal.net](http://eulyncweb01.csmglobal.net)”)and([HTTP::uri] contains"/RequestHandler/Files/UCPhone"} { node 10.96.96.16 80 } else{ "

---

<div class="post-metadata">

**Author:** ![TechT](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@TechT](https://community.f5.com/u/TechT)\
**Post date:** [June 25, 2015, 10:07am UTC](https://community.f5.com/t/irule-not-working/19486/2 "2015-06-25T10:07:04Z")

</div>

Hi Mohanish , try the below :

```tcl
Code

```

when HTTP\_REQUEST { if { ([HTTP::host] contains “[eulyncweb01.csmglobal.net](http://eulyncweb01.csmglobal.net)”) and ([HTTP::uri] contains “/RequestHandler/Files/UCPhone”) } { node 10.96.96.16 } else { HTTP::redirect “https://[HTTP::host][HTTP::uri]” } }

---

<div class="post-metadata">

**Author:** ![TechT](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@TechT](https://community.f5.com/u/TechT)\
**Post date:** [June 25, 2015, 10:14am UTC](https://community.f5.com/t/irule-not-working/19486/3 "2015-06-25T10:14:14Z")

</div>

Hi Mohanish , try the below :

```tcl
when HTTP_REQUEST {
if { ([HTTP::host] contains "eulyncweb01.csmglobal.net") and ([HTTP::uri] contains "/RequestHandler/Files/UCPhone") } {
    node 10.96.96.16 }
else { HTTP::redirect "https://[HTTP::host][HTTP::uri]" }
}

```

---

<div class="post-metadata">

**Author:** ![Mohanish\_169493](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@Mohanish\_169493](https://community.f5.com/u/Mohanish_169493)\
**Post date:** [June 25, 2015, 10:23am UTC](https://community.f5.com/t/irule-not-working/19486/4 "2015-06-25T10:23:54Z")

</div>

Hi Maneesh,

Thanks I will try this out and let you know. However please if you can let me know what is wrong with my above code is it the spacings that are going wrong

---

<div class="post-metadata">

**Author:** ![TechT\_163800](https://avatars.discourse-cdn.com/v4/letter/t/e99b99/32.png) [@TechT\_163800](https://community.f5.com/u/TechT_163800)\
**Post date:** [June 25, 2015, 10:27am UTC](https://community.f5.com/t/irule-not-working/19486/5 "2015-06-25T10:27:01Z")

</div>

Couple of close brace, space were missing and you added port 80 with the node.

---

<div class="post-metadata">

**Author:** ![stan\_piron](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@stan\_piron](https://community.f5.com/u/stan_piron)\
**Post date:** [June 25, 2015, 1:51pm UTC](https://community.f5.com/t/irule-not-working/19486/6 "2015-06-25T13:51:32Z")

</div>

since 11.4, the best way to do what you want is to create a LTM policy. it is easier to configure in GUI and best to see rules.

The following lines allow to create policy in TMSH and create expected rules:

```tcl
create ltm policy /Common/eulyncweb01-HTTP requires add { http } strategy first-match controls add { forwarding }
modify ltm policy /Common/eulyncweb01-HTTP rules add {UCPhone { actions add { 0 { forward select node 10.96.96.16 } } conditions add { 1 { http-host host values { eulyncweb01.csmglobal.net } } 2 { http-uri path contains values { "/RequestHandler/Files/UCPhone" } } } ordinal 1 }}
modify ltm policy /Common/eulyncweb01-HTTP rules add {redirect { actions add { 0 { http-reply redirect location https://[HTTP:host][HTTP::uri] } } ordinal 2 }}

```

and the configuration is: (you can load it with tmsh load sys merge from-terminal

```tcl
ltm policy eulyncweb01-HTTP {
    controls { forwarding }
    requires { http }
    rules {
        UCPhone {
            actions {
                0 {
                    forward
                    select
                    node 10.96.96.16
                }
            }
            conditions {
                1 {
                    http-host
                    host
                    values { eulyncweb01.csmglobal.net }
                }
                2 {
                    http-uri
                    path
                    contains
                    values { /RequestHandler/Files/UCPhone }
                }
            }
            ordinal 1
        }
        redirect {
            actions {
                0 {
                    http-reply
                    redirect
                    location https://[HTTP:host][HTTP::uri]
                }
            }
            ordinal 2
        }
    }
    strategy first-match
}

```
