Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
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.
| |
|
Topic: Need a help with the regexp in Apache 2.4 |
|
Author |
|
EIKA
Joined: 22 Jan 2019 Posts: 43 Location: US
|
Posted: Sun 08 Oct '23 0:43 Post subject: Need a help with the regexp in Apache 2.4 |
|
|
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: 346 Location: UK
|
Posted: Sun 08 Oct '23 22:38 Post subject: |
|
|
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 |
|
|
|
|
|
|