# iRule with User Agent to allow iphone and android, but block all other user agent.

**URL:** <https://community.f5.com/t/irule-with-user-agent-to-allow-iphone-and-android-but-block-all-other-user-agent/39742>\
**Category:** Technical Forums\
**Tags:** irules, ltm, application-delivery\
**Created:** [November 14, 2017, 6:06pm UTC](https://community.f5.com/t/irule-with-user-agent-to-allow-iphone-and-android-but-block-all-other-user-agent/39742 "2017-11-14T18:06:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Scot\_G\_3](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@Thomas\_Scot\_G\_3](https://community.f5.com/u/Thomas_Scot_G_3)\
**Post date:** [November 14, 2017, 6:06pm UTC](https://community.f5.com/t/irule-with-user-agent-to-allow-iphone-and-android-but-block-all-other-user-agent/39742/1 "2017-11-14T18:06:37Z")

</div>

We would like to limit external traffic coming to our portal via F5 to mobile devices only. It should allow PC / Laptop traffic redirect towards another url. I tried the below I rule but always redirecting to the url specified even for mobile users

when HTTP\_REQUEST { if { ![class match [string tolower [HTTP::header “User-Agent”]] contains Mobile\_Access\_Only ] } { continue

```tcl
} else {
    HTTP::redirect "http://xxxx/"
}

```

}

Can someone help on this.

---

<div class="post-metadata">

**Author:** ![Only1masterbla1](https://avatars.discourse-cdn.com/v4/letter/o/a9adbd/32.png) [@Only1masterbla1](https://community.f5.com/u/Only1masterbla1)\
**Post date:** [November 15, 2017, 3:50am UTC](https://community.f5.com/t/irule-with-user-agent-to-allow-iphone-and-android-but-block-all-other-user-agent/39742/2 "2017-11-15T03:50:15Z")

</div>

Looking at your comment, you should not negate if condition. You may log user-agent values for verification.

---

<div class="post-metadata">

**Author:** ![JonArsenault\_34](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@JonArsenault\_34](https://community.f5.com/u/JonArsenault_34)\
**Post date:** [November 16, 2017, 2:10pm UTC](https://community.f5.com/t/irule-with-user-agent-to-allow-iphone-and-android-but-block-all-other-user-agent/39742/3 "2017-11-16T14:10:46Z")

</div>

Hi, I realize you may be here looking for a free fix but my company, ScientiaMobile, offers device intelligence tools that focus on UA parsing. If a fully functional and weekly updated UA parsing service is possibly required for your project please read on.

We track hundreds of millions of user agents and accurately map those to about 60,000 devices currently, and every device is mapped to over 500 data points which helps in making rendering decisions. Facebook, Google, Akamai, PayPal, and many other large companies use us as their device recognition engine.

We track hardware type (phone, tablet, pc, tv, etc), brand, model, marketing name, OS, OS version, screen size, everything you’d need to know to accurately detect, measure, and treat devices on the web.

If you’d be up for a quick conversation shoot me an email at [jon@scientiamobile.com](mailto:jon@scientiamobile.com)
