阻止大家,除了来自特定引荐游客游客

2023-09-02 10:07:57 作者:千山暮雪。

在htaccess的,我怎么能阻止每一位参观者,包括机器人,除了那些谁来自一个特定的域或与特定用户代理?

In htaccess, how can i block every visitor, including bots, except those who come from a specific domain or with a specific user agent?

我必须保护每一页的访问,除了几个允许访问的网页的。

I must protect every page from access, except couple of allowed pages.

大家谁是阻止应该接收自定义通知。

everyone who is blocked should receive a custom notice.

感谢

推荐答案

首先,请允许公共页面,包括禁止消息。然后允许与适当的 的RewriteCond S和发送状态 403 来一切

First allow public pages including the forbidden message. Then allow requests with specific referrer and user agents with the appropriate RewriteConds and send a status 403 to everything else

RewriteEngine on

# allow public pages
RewriteRule ^forbidden.html$ - [L]
RewriteRule ^public1.html$ - [L]
RewriteRule ^public2.html$ - [L]

# serve everyone from specific-domain or specific-user-agent
RewriteCond %{HTTP_REFERER} ^https?://www.specific-domain.com [OR]
RewriteCond %{HTTP_USER_AGENT} ^specific-user-agent$
RewriteRule ^ - [L]

# everybody else receives a forbidden
RewriteRule ^ - [F]

ErrorDocument 403 /forbidden.html