Deny referrals from all domains except one

北城余情 提交于 2019-12-01 11:25:26

Make that something like:

RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !yourdomain\.com [NC]
RewriteCond %{HTTP_REFERER} !alloweddomain\.com [NC]
RewriteRule .? - [F]

The first RewriteCond checks that the referrer is not empty. The second checks that it doesn't contain the string yourdomain.com, and the third that it doesn't contain the string alloweddomain.com. If all of these checks pass, the RewriteRule triggers and denies the request.

(Allowing empty referrers is generally a good idea, since browsers can generate them for various reasons, such as when:

  • the user has bookmarked the link,
  • the user entered the link manually into the address bar,
  • the user reloaded the page,
  • the browser is configured not to send cross-site referrer infromation, or
  • a proxy between your site and the browser strips away the referrer information.)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!