# iRule exclude URI

**URL:** <https://community.f5.com/t/irule-exclude-uri/71027>\
**Category:** Technical Forums\
**Tags:** devops\
**Created:** [November 22, 2022, 9:20pm UTC](https://community.f5.com/t/irule-exclude-uri/71027 "2022-11-22T21:20:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Pintel](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Alex\_Pintel](https://community.f5.com/u/Alex_Pintel)\
**Post date:** [November 22, 2022, 9:20pm UTC](https://community.f5.com/t/irule-exclude-uri/71027/1 "2022-11-22T21:20:07Z")

</div>

I am fairly new to iRules so any help greately appreciated.

What is correct syntax to exclude URI "/abc/Web123/cde/forum123/ from receiving HTTP code 200 and the message “123456789”? Is the exclamation mark a orrect synatx to exclude URI?

Here is iRule

when HTTP\_REQUEST {  
set http\_path [string tolower [HTTP::path]]  
if { ! ($http\_path starts\_with “/abc/Web123/cde/forum123”) } {  
HTTP::respond 200 content "  
\<html\>  
\<head\>  
\<title\>\</title\>  
\</head\>  
\<body\>  
123456789  
\</body\>  
\</html\>  
"  
}  
}

Thank you for any assistamce you can provide.

---

<div class="post-metadata">

**Author:** ![mihaic](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/mihaic/32/2175_2.png) [@mihaic](https://community.f5.com/u/mihaic)\
**Post date:** [November 23, 2022, 6:42am UTC](https://community.f5.com/t/irule-exclude-uri/71027/2 "2022-11-23T06:42:02Z")

</div>

As far as i know you can use ! or NOT.

Here are the operators list:

> **[Operators](https://clouddocs.f5.com/api/irules/Operators.html)**

---

<div class="post-metadata">

**Author:** ![CA\_Valli](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@CA\_Valli](https://community.f5.com/u/CA_Valli)\
**Post date:** [November 23, 2022, 1:21pm UTC](https://community.f5.com/t/irule-exclude-uri/71027/3 "2022-11-23T13:21:24Z")

</div>

Hello, if you’re looking to exclude an exact match for a string, “ne” operator can be used as well.

One thing I noticed -- since this is an exact match, be careful with “string tolower” syntax as it will convert everything to lowercase, so **you will never see Web123 -- it’s gonna be web123 instead.**

I generally don’t recommend converting paths to lowercase since it is case sensitive, try using this instead:

```tcl
if { [HTTP::path] ne "/abc/Web123/cde/forum123" }{ ... }

```

---

<div class="post-metadata">

**Author:** ![Mohamed\_Ahmed\_Kansoh](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/mohamed_ahmed_kansoh/32/10886_2.png) [@Mohamed\_Ahmed\_Kansoh](https://community.f5.com/u/Mohamed_Ahmed_Kansoh)\
**Post date:** [November 23, 2022, 1:46pm UTC](https://community.f5.com/t/irule-exclude-uri/71027/4 "2022-11-23T13:46:53Z")

</div>

Hi&nbsp; @Alex_Pintel &nbsp;,&nbsp;  
Could you please try this :

```tcl
when HTTP_REQUEST {
#set http_path [string tolower [HTTP::path]]
if { [HTTP::path] ne "/abc/Web123/cde/forum123" } {
HTTP::respond 200 content "
<html>
<head>
<title></title>
</head>
<body>
123456789
</body>
</html>
"
}
}

```

I tested it on my lab and it works well.&nbsp;  
Regards

---

<div class="post-metadata">

**Author:** ![Amine\_Kadimi](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@Amine\_Kadimi](https://community.f5.com/u/Amine_Kadimi)\
**Post date:** [November 23, 2022, 2:54pm UTC](https://community.f5.com/t/irule-exclude-uri/71027/5 "2022-11-23T14:54:37Z")

</div>

To negate starts\_with I would use the not operator:

> **[not](https://clouddocs.f5.com/api/irules/not.html)**

```tcl
when HTTP_REQUEST {
  if { not ([HTTP::uri] starts_with "/abc") } {
     # do something ...
  } else {
     # do something else...
 }
}

```

For excluding the exact path, you can go with&nbsp; the “ne” operator

---

<div class="post-metadata">

**Author:** ![Alex\_Pintel](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Alex\_Pintel](https://community.f5.com/u/Alex_Pintel)\
**Post date:** [November 23, 2022, 5:08pm UTC](https://community.f5.com/t/irule-exclude-uri/71027/6 "2022-11-23T17:08:23Z")

</div>

Thank you all for responding to my post. I have another question.

What would be right syntax if I need to use 2 URLs?

```tcl
if { [HTTP::path] ne "/abc/Web123/cde/forum123" OR "/abc/Web123/cde/forum456"

```

Is the “OR” correct operator?

Thank you!

---

<div class="post-metadata">

**Author:** ![Amine\_Kadimi](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@Amine\_Kadimi](https://community.f5.com/u/Amine_Kadimi)\
**Post date:** [November 24, 2022, 8:08am UTC](https://community.f5.com/t/irule-exclude-uri/71027/7 "2022-11-24T08:08:45Z")

</div>

For the requested logic, you need the “and” operator between two tests:

```tcl
if { ([HTTP::path] ne "/abc/Web123/cde/forum123") and ([HTTP::path] ne "/abc/Web123/cde/forum456") }

```

If you plan to add more paths in the future, then consider using a [switch](https://clouddocs.f5.com/api/irules/switch.html) test
