0

I need to work with some user-agents in Apache 2.4. I googled a lot for examples, tried a million regex options, and it still doesn't work:

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

Meanwhile, RegExp as such works fine (see https://regexr.com/7lar4 ). And it clearly points to my wrong homebrew Apache syntax.

This is what I already tried as well:

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

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

And so on. Nothing worked.

Please advise!

1 Answer 1

0

After wasting another hour, I can say that the correct syntax is:

<FilesMatch ".+\.(?=(doc|docx|pdf|ppt|rtf|xls|xlsx)$)[^\.]+?$">
<If "%{HTTP_USER_AGENT} =~ /^.*(Googlebot|Google-InspectionTool|GoogleOther|GoogleOther|bingbot|YandexBot|YandexImages|YandexMetrika|YandexWebmaster|Baiduspider).*$/">
Require all granted
</If>
</FilesMatch>

This config part will allow major bots to crawl office files.

Apache 2.4 of abore is required.

You must log in to answer this question.

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