G
G
golf4man2020-07-23 23:39:25
htaccess
golf4man, 2020-07-23 23:39:25

How to disable empty referrers in .htaccess but allow search bots?

So, the task is as follows:

All direct visits to the site should be blocked, i. these are visits with an empty referrer. I do it like this:

RewriteEngine on 
RewriteCond %{HTTP_REFERER} ^$ 
RewriteRule^- [F,L]

Everything works correctly, except that in addition to direct visits, search bots are also blocked, which I cannot do. Please, tell me, using the example of one bot, how this can be written in .htaccess.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2020-07-24
@dodo512

Search bots specify the From header.

RewriteCond %{HTTP_REFERER} ^$
RewriteCond %{HTTP:FROM} !(googlebot|yandex)
RewriteRule ^ - [F]

S
SagePtr, 2020-07-23
@SagePtr

But what if the referrer -Policy of the site from which they are redirecting prohibits the transfer of referrers? Then the browser will not transmit this header, and your site will block the visitor. Why such discrimination? And how will it save from an attacker who can easily forge the Referrer header?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question