3

I've tried ||, OR without success, so what is the more concise way to write these two matches on the user agent in a single statement?

<If "%{HTTP_USER_AGENT} == 'Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1'">
  Require all denied
</If>
<If "%{HTTP_USER_AGENT} == 'Mozilla/5.0 (Windows NT 6.1; WOW64)'">
  Require all denied
</If>

2 Answers 2

9

Are you sure you did not make any syntax mistakes?

Usage of || is done this way and it works fine:

<If "%{HTTP_USER_AGENT} == 'Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1' || %{HTTP_USER_AGENT} == 'Mozilla/5.0 (Windows NT 6.1; WOW64)'">
    Require all denied
</If>

Reference for expressions in Apache HTTP:

https://httpd.apache.org/docs/current/expr.html

1
  • 7
    This very works. The OR condition || must be within the <If> statement's double quotes "" as a single expression. E.g. "something || something", not "something" || "something".
    – Adambean
    Commented Jun 3, 2020 at 10:20
1

You can use regexp:

<If "%{HTTP_USER_AGENT} =~ /Mobile/">
   Require all denied
</If>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .