logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Need a help with the regexp in Apache 2.4
Author
EIKA



Joined: 22 Jan 2019
Posts: 43
Location: US

PostPosted: Sun 08 Oct '23 0:43    Post subject: Need a help with the regexp in Apache 2.4 Reply with quote

Hi all!

I need to catch some user-agents. Googled a lot for examples, tried a million of regexp options, and it still doesn't work:

Code:
<If "%{HTTP_USER_AGENT} == '/^.*(Google|bing|Windows|Gecko).*$/'">
Require all granted
</If>

But RE doesn't work.

Menwhile, RegExp as such works fine. And it clearly points to my wrong homebrew Apache syntax.

This is what I already tried as well:
[code]<If "%{HTTP_USER_AGENT} == '^.*(Google|bing|Windows|Gecko).*$'">
Require all granted
</If>

[code]<If "%{HTTP_USER_AGENT} == '~/^.*(Google|bing|Windows|Gecko).*$/'">
Require all granted
</If>
[/code]
And so on.

Nothing worked.

Please advise!
Back to top
tangent
Moderator


Joined: 16 Aug 2020
Posts: 315
Location: UK

PostPosted: Sun 08 Oct '23 22:38    Post subject: Reply with quote

Try the following:

Code:
<If "%{HTTP_USER_AGENT} =~ /(Google|bing|Windows|Gecko)/i">
  Require all granted
</If>

I've removed the single quotes, also gone for regex match rather than equality, and finally requested a case insensitive match.

See https://httpd.apache.org/docs/2.4/expr.html for other syntax examples.
Back to top


Reply to topic   Topic: Need a help with the regexp in Apache 2.4 View previous topic :: View next topic
Post new topic   Forum Index -> Apache